首页 > 解决方案 > React Native 应用程序无法在 android 上编译,可能与 AndroidX 有关

问题描述

我在让我的项目在 android 上运行时遇到问题:

> Task :react-native-fast-image:compileDebugJavaWithJavac FAILED
Gradle may disable incremental compilation as the following annotation processors are not incremental: jetified-compiler-4.7.1.jar (com.github.bumptech.glide:compiler:4.7.1).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule, com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule]
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:6: error: package android.support.annotation does not exist
import android.support.annotation.CheckResult;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:7: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideRequest.java:8: error: package android.support.annotation does not exist
import android.support.annotation.CheckResult;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideRequest.java:9: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideRequests.java:7: error: package android.support.annotation does not exist
import android.support.annotation.CheckResult;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideRequests.java:8: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/bumptech/glide/GeneratedRequestManagerFactory.java:4: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/bumptech/glide/GeneratedAppGlideModuleImpl.java:4: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:48: error: cannot find symbol
  @CheckResult
   ^
  symbol:   class CheckResult
  location: class GlideOptions
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:49: error: cannot find symbol
  @NonNull
   ^
  symbol:   class NonNull
  location: class GlideOptions
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:57: error: cannot find symbol
  @CheckResult
   ^
  symbol:   class CheckResult
  location: class GlideOptions
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:58: error: cannot find symbol
  @NonNull
   ^
  symbol:   class NonNull
  location: class GlideOptions
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:66: error: cannot find symbol
  @CheckResult
   ^
  symbol:   class CheckResult
  location: class GlideOptions
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java:67: error: cannot find symbol
  @NonNull
   ^
 .
 .
 .
 More errors like these...
 .
 .
 .

  symbol:   class NonNull
  location: class GeneratedAppGlideModuleImpl
/Users/usr/Documents/Company/Company-mobile/node_modules/react-native-fast-image/android/build/generated/source/apt/debug/com/bumptech/glide/GeneratedAppGlideModuleImpl.java:53: error: cannot find symbol
  @NonNull
   ^
  symbol:   class NonNull
  location: class GeneratedAppGlideModuleImpl
90 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-fast-image:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 11s
45 actionable tasks: 2 executed, 43 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.

我努力了:

这是我的android/build.gradle样子:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0' //previously 3.2.0
        classpath 'com.google.gms:google-services:4.2.0'

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

//cocoa pods was creating duplicates of dependencies and this was the only thing that solved it.
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

这就是我的android/app/build.gradle样子:p

roject.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.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 = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.mobileapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 23
        versionName "1.1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    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 = ["armeabi-v7a":1, "x86":2]
            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
            }
        }
    }
}

dependencies {
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-firebase')
    implementation project(':react-native-push-notification')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-svg')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-document-picker')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-svg')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-document-picker')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    //Firebase dependencies
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation "com.google.firebase:firebase-core:16.0.6"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
}

// 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'

任何提示都有帮助!

谢谢你。

标签: androidreact-native

解决方案


推荐阅读