任务':react-native-camera:compileDebugJavaWithJavac'的执行失败

Тем*_*тов 8 android gradle android-gradle-plugin react-native react-native-android

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

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'. 在“构建->运行任务”(Android Studio)中。

关于Java编译器,大约有20-30错误,所有这些都显示以下内容:error: package android.support.annotation does not existerror: package android.support.v4.util does not existerror: package android.support.media does not exist,等,或error: cannot find symbol class SparseArrayCompaterror: package Pools does not existerror: cannot find symbol variable 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")
}
Run Code Online (Sandbox Code Playgroud)

我的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"
}
Run Code Online (Sandbox Code Playgroud)

我的解决方案尝试:

  • 我将android-support-v4.jar文件添加到了./libs文件夹中。
  • 我将“ google()”或maven链接添加到依赖项。
  • 我尝试更改minSdkVersion,compileVersion等无济于事,但我想这可能是主要问题。
  • 重建项目也不起作用。
  • 将项目迁移到AndroidX。

我的SDK版本:28

摇篮版本:4.10.1

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

Gee*_*lam 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+"
    }
}
Run Code Online (Sandbox Code Playgroud)

反应本机相机/android/build.gradle

android {
   compileSdkVersion 28
   buildToolsVersion "28.0.3"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName computeVersionName()
}
lintOptions {
    abortOnError false
}
}
Run Code Online (Sandbox Code Playgroud)