目前,我正在尝试连接的react本机通过外部库。我已经成功地在一个本地的react本地项目中桥接了它,目前正在创建库中的android部分。
目前我使用的是当前的实现,当我尝试运行android版本时,我遇到了这个错误:
sdk生活在我的外部库中的{libraryname}/android/app/libs中。
我在外部库中的android/app build.gradle看起来像这样。
apply plugin: 'com.android.library'
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 28)
buildToolsVersion safeExtGet("buildToolsVersion", '28.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 17)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0" nb
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// React Native
implementation "com.facebook.react:react-native:+"
// HereMaps SDK
implementation(name:'HERE-sdk', ext:'aar')
}和安卓级别的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 17
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
flatDir {
dirs 'libs'
}
}
}在react本机方面,我在android/app级别上的build.gradle只进行了以下更改:
dependencies {
implementation project('{project-name}')
}我的settings.gradle包括以下更改:
include ':{library name}'
project(':{library name}').projectDir = new File(rootProject.projectDir, '../node_modules/{library name}/android/app')最后在我的MainApplication.java中:
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for
// example:
packages.add(new HeremapsPackage()); //<------added this line
return packages;
}知道我在这里错过了什么吗?我想避免添加sdk在我的主要反应-本机应用程序,因为这是接近100 my。谢谢!
发布于 2020-02-24 07:31:39
gradle buildTypes在根级和应用程序级别上应该是相同的,以解决依赖关系。另外,如果您使用的是lite版本,您可以考虑升级sdk的版本。
buildTypes{调试{.}释放{.}
在您的(app) build.gradle文件中,必须包含所有名称相同的buildTypes{ }
buildTypes{调试{.}释放{.}
包含在项目中的所有库/模块的build.gradle文件。
清理和重建项目,问题应得到解决。
https://stackoverflow.com/questions/60310463
复制相似问题