任务":react-native-background-job:compileDebugJavaWithJavac"的执行失败。在执行反应本机后台作业时?



在制作React Antive应用程序时,我会收到以下错误。.我在下面附加了错误和gradle文件。我还尝试使用EnableJetifier迁移到Androidx,并且Useandroidx既真实又干净,但仍然没有运气。

  • 出了什么问题:执行失败的任务':react-native-background-job:compiledebugjavawithjavac'

错误:

> Task :react-native-background-job:compileDebugJavaWithJavac
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobReactNativeEventStarter.java:7: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobBackgroundJobModule.java:7: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobExactJob.java:6: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobUtils.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobReactNativeEventStarter.java:29: error: cannot find symbol
  ReactNativeEventStarter(@NonNull Context context) {
                           ^
  symbol:   class NonNull
  location: class ReactNativeEventStarter
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobReactNativeEventStarter.java:34: error: cannot find symbol
  public void trigger(@NonNull Bundle jobBundle) {
                       ^
  symbol:   class NonNull
  location: class ReactNativeEventStarter
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobBackgroundJobModule.java:146: error: cannot find symbol
  @Nullable @Override public Map<String, Object> getConstants() {
   ^
  symbol:   class Nullable
  location: class BackgroundJobModule
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobExactJob.java:14: error: cannot find symbol
  @Override protected void onHandleIntent(@Nullable Intent intent) {
                                           ^
  symbol:   class Nullable
  location: class ExactJob
C:UsersDellDesktopProjectsGetz Newappnode_modulesreact-native-background-jobandroidsrcmainjavacompilloxabackgroundjobUtils.java:14: error: cannot find symbol
  public static boolean isReactNativeAppInForeground(@NonNull ReactNativeHost reactNativeHost) {
                                                      ^
  symbol:   class NonNull
  location: class Utils
9 errors.
 What went wrong:
Execution failed for task ':react-native-background-job:compileDebugJavaWithJavac'

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
        minSdkVersion = 21
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.3"
    }
 repositories {
        jcenter()
        google()
    }
    dependencies {
        // Specifically 3.0.1: concidered stable
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven { url "https://jitpack.io" } 
                maven { url 'https://maven.google.com' }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

build.gradle/app:


apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
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
    buildToolsVersion "28.0.3"

    dexOptions {
        preDexLibraries = false
    }
    defaultConfig {
        applicationId "com.dd.medworks"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 3
        versionName "2.1"
        ndk {
            abiFilters "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
            }
        }
    }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk true  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            shrinkResources false
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
            manifestPlaceholders = [excludeSystemAlertWindowPermission: "true"]
        }
          debug {
            manifestPlaceholders = [excludeSystemAlertWindowPermission: "false"]
        } 
    }
    // 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
            }
        }
    }
     lintOptions {
        checkReleaseBuilds false
    }
}
dependencies {
      //compile project(':react-native-background-task')
      compile(project(':react-native-svg')) {
        exclude group: "com.android.support", module: "appcompat-v7"
    }
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile project(':react-native-charts-wrapper')
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile files('libs/dnurseexttestlib.jar')
    compile 'me.tankery.lib:circularSeekBar:1.1.7'
    compile 'com.facebook.fresco:animated-gif:1.3.0'
    compile project(':react-native-push-notification')
     compile 'com.google.firebase:firebase-messaging:+'
      implementation 'com.google.firebase:firebase-core:+'
      compile 'com.google.android.gms:play-services-analytics:+'
    compile ('com.google.android.gms:play-services-gcm:17.0.0') {
        force = false;
    }
    //       compile (project(':react-native-fcm')){
    //     exclude group: "com.google.firebase" 
    // }
    implementation project(':rn-fetch-blob')   
      compile project(':react-native-pdf')  
      compile project(':react-native-background-job') 
}
// 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'
}

需要在AndroidX。

中迁移

确实在您的库中更改

ex:android.support.annotation.nonnull更改为androidx.annotation.nonnull

https://developer.android.com/jetpack/androidx/migrate

或尝试此https://github.com/facebook/react-native/issues/21722

Androidx,Android.Support已淘汰,使用Androidx,而在给定的节点模块路径中导入Androidx。希望这将起作用

最新更新