[英]Task :react-native-camera:compileGeneralDebugJavaWithJavac FAILED
[英]Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'
我正在使用 React-Native 创建应用程序并在 Android 设备上对其进行测试。 添加react-native-camera模块后,出现如下错误:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'.
在“构建 - >运行任务”(Android Studio)。
Concerning the Java compiler, there are about 20-30 errors, all of which show the following: error: package android.support.annotation does not exist
, error: package android.support.v4.util does not exist
, error: package android.support.media does not exist
等或error: cannot find symbol class SparseArrayCompat
, error: package Pools does not exist
, error: cannot find symbol variable ExifInterface
,在错误文件中检查时与import android.support.v4.util.ArrayMap;
-导入类语句。
我的 android/build.gradle 文件:
buildscript {
ext {
minSdkVersion = 26
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
mavenLocal()
jcenter()
/*maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
//url "$rootDir/../node_modules/react-native/android"
url "https://maven.google.com"
}*/
google()
}
}
tasks.withType(Wrapper) {
gradleVersion = "4.10.1"
distributionUrl = distributionUrl.replace("bin", "all")
}
我的 app/build.gradle 文件:
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.helloworld"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
productFlavors {
}
}
dependencies {
implementation (project(':react-native-camera')) {
exclude group: 'com.google.android.gms'
exclude group: "com.android.support"
implementation 'com.android.support:exifinterface:28.0.0'
implementation ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
implementation project(':react-native-orientation')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-vector-icons')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-spinkit')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation ('com.facebook.react:react-native:0.58.3')
implementation "com.android.support:support-v4:28.0.0"
//implementation "androidx.legacy:legacy-support-v4:1.0.0"
}
我的解决方案尝试:
我的 SDK 版本:28
Gradle 版本:4.10.1
classpath 'com.android.tools.build.gradle:3.3.1'(将 gradle 版本降级到 3.1.0 无效)。
使用您的应用程序构建 gradle 属性更改 react-native-camera build.gradle 文件中的 minsdk 版本和 compilesdk 版本。
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "16.1.0" // or set latest version
androidMapsUtilsVersion = "0.5+"
}
}
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName computeVersionName()
}
lintOptions {
abortOnError false
}
}
结帐平台的特定要求......例如在android上检查权限至少应该是:
<uses-permission android:name="android.permission.CAMERA" />
在根目录下运行:
npx jetify
最近由于react-native 问题,我在所有工作项目中都遇到了错误。 我的本机反应版本是 0.61.5
参考
针对旧版 react-native (< 0.63)的修复:上述修复仅适用于 gradle 6.2 及更高版本。 旧 react-native 使用旧 gradle。
我只是将我的 gradle 版本从 5.5 更改为 6.2。 它对我有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.