android - 错误 : package com. android.annotations 不存在

标签 android react-native android-studio gradle android-gradle-plugin

我有以下类(class)

import com.android.annotations.NonNullByDefault;

@NonNullByDefault
public final class Log {
    ...
}

这是我的 build.gradle 文件(省略了一些部分)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '24.0.1'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 2
        versionName "0.2"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}

dependencies {    
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:support-annotations:25.0.0'
    compile 'com.android.support:design:25.0.0'
}

在 Android Studio 中,我的类(class)没有发出警告

enter image description here

但是,当我尝试构建并运行我的应用程序时,我从 gradle 收到此错误

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
Warning:[options] bootstrap class path not set in conjunction with -source 1.7
/home/puter/git-repos/TaskManager3/app/src/main/java/com/treemetrics/taskmanager3/util/Log.java
Error:(3, 31) error: package com.android.annotations does not exist
Error:(7, 2) error: cannot find symbol class NonNullByDefault
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 21.021 secs
Information:3 errors
Information:1 warning
Information:See complete output in console

最佳答案

自动修复 React Native 的所有 android 到 androidx 问题(先决条件 npx)

将以下两个标志添加到 ProjectFolder/android/gradle.propertiesgradle.properties 文件中的 true

android.useAndroidX=true
android.enableJetifier=true

执行

npm install --save-dev jetifier
npx jetify
npx react-native run-android

在 package.json 中将以下内容添加到脚本中

  "postinstall" : "npx jetify"

更多信息请访问 https://github.com/mikehardy/jetifier

更新:它现在内置于react-native 0.60中。如果您迁移到react-native 0.60,则不需要此步骤。 -https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support

关于android - 错误 : package com. android.annotations 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380519/

相关文章:

Android InApp 购买错误代码 102

android - AlarmManager.set不准确重复问题

react-native - 如何在不调用每个 'Text' 组件的情况下一次全局设置自定义字体系列并在整个 react-native 应用程序中使用?

java - 当软键盘出现时,使用 Recycler View 调整布局大小

java - 如何解决任务 ':app:mergeDebugResources' 执行失败的问题。在 Android Studio 3.6.2 中

ios - iOS 和 Android 上的 Container 高度不一样

安卓 : how to initialize an activity in background before displaying it

java - Robospice-改造测试

javascript - Firestore orderBy Timestamp DESC

javascript - 无法读取未定义的属性 'initSdk' - Appsflyer 集成 React Native