react native 运行 android 有错误。解决错误后无法更改配置 ':packagename:androidApis' 的依赖项
react native run android has an error. Cannot change dependencies of configuration ':packagename:androidApis' after it has been resolved error
我有一个 React Native 项目,其中包含许多库,例如 React Native Fetch Blob、React Native Camera 等。
对于 运行 项目,我克隆了我的存储库并安装了节点模块,因此 运行 react-native 运行 命令遇到以下错误:
经过几个小时的搜索和尝试,我无法解决问题。之后,我从项目中删除了 React Native Fetch Blob 并再次 运行 android 所以 React Native Camera
遇到了新的错误
我认为这个错误在我的 android 配置中出现并且不需要 React Native 库。
android > 应用 > build.gradle
apply plugin: "com.android.application"
apply plugin: "io.fabric"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
project.ext.envConfigFiles = [
debug : ".env.development",
release : ".env.production",
anothercustombuild: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = true
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = true
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "**.***.*****"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.env.get("ANDROID_VERSION_CODE") as Integer
versionName project.env.get("ANDROID_VERSION_NAME")
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
signingConfigs {
release {
if (project.env.get("ANDROID_RELEASE_STORE_FILE")) {
storeFile file(project.env.get("ANDROID_RELEASE_STORE_FILE"))
storePassword project.env.get("ANDROID_RELEASE_STORE_PASSWORD")
keyAlias project.env.get("ANDROID_RELEASE_KEY_ALIAS")
keyPassword project.env.get("ANDROID_RELEASE_KEY_PASSWORD")
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) + defaultConfig.versionCode * 100
} else {
output.versionCodeOverride = defaultConfig.versionCode * 100
}
}
}
}
dependencies {
implementation project(':react-native-config')
implementation project(':react-native-camera')
implementation project(':react-native-vector-icons')
implementation project(':react-native-spinkit')
implementation project(':react-native-share')
implementation project(':react-native-image-resizer')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-splash-screen')
implementation project(':react-native-i18n')
implementation project(':rn-fetch-blob')
implementation project(':react-native-image-picker')
implementation project(':react-native-fs')
implementation project(':react-native-contacts')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-view-shot')
implementation project(':react-native-picker')
implementation project(':react-native-document-picker')
implementation project(':react-native-exit-app')
implementation project(':react-native-firebase')
compile('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
transitive = true;
}
implementation project(':react-native-device-info')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
// From node_modules
// Firebase dependencies
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
compile 'com.android.support:multidex:1.0.0'
compile project(':react-native-file-opener1')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
android > build.gradle 文件是:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.0")
classpath 'com.google.gms:google-services:4.0.2'
classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
maven { url "https://jitpack.io" }
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
configurations.all {
resolutionStrategy.force 'com.google.android.gms:play-services-gcm:16.1.0', 'com.google.android.gms:play-services-basement:15.0.1'
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
all*.exclude group: 'com.squareup.okio', module: 'okio'
resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.10.0'
all*.exclude group: 'com.github.bumptech.glide', module: 'glide'
all*.exclude group: 'org.litepal.android', module: 'core'
}
}
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
谁能帮我解决这个问题???
这对我来说是一个令人困惑的问题。为了解决这个问题,我做了一些步骤:
1) 如下更改 ext 变量:
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "27.1.1"
}
2) 增加react native版本到
"react-native": "0.59.8",
3) 在 gradle.properties
文件中启用 androidX:
android.useAndroidX=true
android.enableJetifier=true
4) 在我的 java 和清单文件中将 appcompat 库导入更改为 AndroidX 库。例如,我是这样改的:
<provider android:name="android.support.v4.content.FileProvider" ...
对此:
<provider android:name="androidx.core.content.FileProvider" ...
5) 安装 jetifier
6) 运行 npx jetifier
7) 运行 npx react-native run-android
到 运行 android 项目
8) 享受你可爱的应用程序
我有一个 React Native 项目,其中包含许多库,例如 React Native Fetch Blob、React Native Camera 等。
对于 运行 项目,我克隆了我的存储库并安装了节点模块,因此 运行 react-native 运行 命令遇到以下错误:
经过几个小时的搜索和尝试,我无法解决问题。之后,我从项目中删除了 React Native Fetch Blob 并再次 运行 android 所以 React Native Camera
遇到了新的错误我认为这个错误在我的 android 配置中出现并且不需要 React Native 库。
android > 应用 > build.gradle
apply plugin: "com.android.application"
apply plugin: "io.fabric"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
project.ext.envConfigFiles = [
debug : ".env.development",
release : ".env.production",
anothercustombuild: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = true
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = true
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "**.***.*****"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.env.get("ANDROID_VERSION_CODE") as Integer
versionName project.env.get("ANDROID_VERSION_NAME")
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
signingConfigs {
release {
if (project.env.get("ANDROID_RELEASE_STORE_FILE")) {
storeFile file(project.env.get("ANDROID_RELEASE_STORE_FILE"))
storePassword project.env.get("ANDROID_RELEASE_STORE_PASSWORD")
keyAlias project.env.get("ANDROID_RELEASE_KEY_ALIAS")
keyPassword project.env.get("ANDROID_RELEASE_KEY_PASSWORD")
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) + defaultConfig.versionCode * 100
} else {
output.versionCodeOverride = defaultConfig.versionCode * 100
}
}
}
}
dependencies {
implementation project(':react-native-config')
implementation project(':react-native-camera')
implementation project(':react-native-vector-icons')
implementation project(':react-native-spinkit')
implementation project(':react-native-share')
implementation project(':react-native-image-resizer')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-splash-screen')
implementation project(':react-native-i18n')
implementation project(':rn-fetch-blob')
implementation project(':react-native-image-picker')
implementation project(':react-native-fs')
implementation project(':react-native-contacts')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-view-shot')
implementation project(':react-native-picker')
implementation project(':react-native-document-picker')
implementation project(':react-native-exit-app')
implementation project(':react-native-firebase')
compile('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
transitive = true;
}
implementation project(':react-native-device-info')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
// From node_modules
// Firebase dependencies
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
compile 'com.android.support:multidex:1.0.0'
compile project(':react-native-file-opener1')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
android > build.gradle 文件是:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.0")
classpath 'com.google.gms:google-services:4.0.2'
classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
maven { url "https://jitpack.io" }
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
configurations.all {
resolutionStrategy.force 'com.google.android.gms:play-services-gcm:16.1.0', 'com.google.android.gms:play-services-basement:15.0.1'
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
all*.exclude group: 'com.squareup.okio', module: 'okio'
resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.10.0'
all*.exclude group: 'com.github.bumptech.glide', module: 'glide'
all*.exclude group: 'org.litepal.android', module: 'core'
}
}
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
谁能帮我解决这个问题???
这对我来说是一个令人困惑的问题。为了解决这个问题,我做了一些步骤:
1) 如下更改 ext 变量:
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "27.1.1"
}
2) 增加react native版本到
"react-native": "0.59.8",
3) 在 gradle.properties
文件中启用 androidX:
android.useAndroidX=true
android.enableJetifier=true
4) 在我的 java 和清单文件中将 appcompat 库导入更改为 AndroidX 库。例如,我是这样改的:
<provider android:name="android.support.v4.content.FileProvider" ...
对此:
<provider android:name="androidx.core.content.FileProvider" ...
5) 安装 jetifier
6) 运行 npx jetifier
7) 运行 npx react-native run-android
到 运行 android 项目
8) 享受你可爱的应用程序