【问题标题】:Execution failed for task ':react-native-background-job:compileDebugJavaWithJavac'. while executing react-native-background-job?任务“:react-native-background-job:compileDebugJavaWithJavac”执行失败。在执行 react-native-background-job 时?
【发布时间】:2019-11-08 01:07:21
【问题描述】:

在构建 react native 应用程序时,我收到以下错误。我在下面附加了错误和 gradle 文件。我也尝试使用 enableJetifier 迁移到 androidX 并多次使用 AndroidX 既真实又干净的 gradle,但仍然没有运气。

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

错误:

> Task :react-native-background-job:compileDebugJavaWithJavac
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\ReactNativeEventStarter.java:7: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\BackgroundJobModule.java:7: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\ExactJob.java:6: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\Utils.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\ReactNativeEventStarter.java:29: error: cannot find symbol
  ReactNativeEventStarter(@NonNull Context context) {
                           ^
  symbol:   class NonNull
  location: class ReactNativeEventStarter
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\ReactNativeEventStarter.java:34: error: cannot find symbol
  public void trigger(@NonNull Bundle jobBundle) {
                       ^
  symbol:   class NonNull
  location: class ReactNativeEventStarter
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\BackgroundJobModule.java:146: error: cannot find symbol
  @Nullable @Override public Map<String, Object> getConstants() {
   ^
  symbol:   class Nullable
  location: class BackgroundJobModule
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\ExactJob.java:14: error: cannot find symbol
  @Override protected void onHandleIntent(@Nullable Intent intent) {
                                           ^
  symbol:   class Nullable
  location: class ExactJob
C:\Users\Dell\Desktop\Projects\Getz New\app\node_modules\react-native-background-job\android\src\main\java\com\pilloxa\backgroundjob\Utils.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'
}



【问题讨论】:

    标签: android react-native gradle react-native-android androidx


    【解决方案1】:

    在 androidx 之后, android.support 已经过时,在导入时使用 androidx 而不是在给定节点模块路径中关闭 android.support 。希望这会奏效

    【讨论】:

      【解决方案2】:

      需要在android X中迁移。

      改变你的图书馆

      例如:android.support.annotation.NonNull 更改为 androidx.annotation.NonNull

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

      或 试试这个https://github.com/facebook/react-native/issues/21722

      【讨论】:

      • 感谢您的快速回复,但是当我通过工作室迁移到 andriodx 时,提示框弹出“项目中未找到任何用法”
      • android.enableJetifier:设置为 true 时,Android 插件会自动迁移现有的第三方库以通过重写其二进制文件来使用 AndroidX。如果未指定该标志,则默认为 false。
      • 嗨@SajjadRaza,即使我弹出“在项目中找不到使用”的提示,你解决了吗?
      • 嗨@Sathvik Nasani 抱歉回复晚了,我设法解决了这个问题,它是某种黑客或其他东西,但它对我有用,问题是在我的一个依赖项中(react-native -inappbrowser-reborn) 导致出现“注释不存在”错误的问题。所以我只是评论了(实现'com.facebook.infer.annotation:infer-annotation:+'),你可以在node_modules->react-native-inappbrowser-reborn->android->build.gradle中找到它。也许在你的情况下,其他一些依赖会导致问题找到它,然后试一试。
      猜你喜欢
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多