任务“:react-native-camera:compileDebugJavaWithJavac”的执行失败。

11

我正在使用React-Native创建应用程序,并在Android设备上进行测试。在添加了react-native-camera模块之后,会出现以下错误:

org.gradle.api.tasks.TaskExecutionException:执行任务“:react-native-camera:compileDebugJavaWithJavac”失败。 在“Build->Run Tasks”(Android Studio)中。

关于Java编译器,大约有20-30个错误,全部显示如下:error:包android.support.annotation不存在error:包android.support.v4.util不存在error:包android.support.media不存在等。
或者是error:找不到符号类SparseArrayCompaterror:包Pools不存在error:找不到符号变量ExifInterface,当检查错误文件时,这与import android.support.v4.util.ArrayMap;-import类型的语句有关。

我的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"
}

我的尝试解决方案:

  • 我将android-support-v4.jar文件添加到./libs文件夹中。
  • 我在依赖项中添加了“google()”或maven链接。
  • 我尝试更改minSdkVersion,compileVersion等,但没有帮助,但我猜这可能是主要问题所在。
  • 重建项目也没有起作用。
  • 将项目迁移到Android X。

我的SDK版本:28

Gradle版本:4.10.1

classpath 'com.android.tools.build:gradle:3.3.1'(将Gradle版本降级为3.1.0也无效)。

4个回答

2

请在您的应用程序构建gradle属性中更改react-native-camera build.gradle文件中的minsdk版本和compilesdk版本。

android/build.gradle

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+"
    }
}

react-native-camera/android/build.gradle

android {
   compileSdkVersion 28
   buildToolsVersion "28.0.3"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName computeVersionName()
}
lintOptions {
    abortOnError false
}
}

0

在根目录下运行:

npx jetify

0

最近由于react-native问题,我在所有的工作项目中都遇到了错误。我的React Native版本是0.61.5。

关于此事:

修复旧版react-native(小于0.63)的方法: 上述修复仅适用于gradle 6.2及更高版本。旧版的react-native使用了旧版gradle。

我刚把我的gradle版本从5.5改成了6.2。这对我起作用了 :)


-1

结账平台特定要求...例如在安卓上,检查权限至少应为:

<uses-permission android:name="android.permission.CAMERA" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接