我有以下类(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)没有发出警告
但是,当我尝试构建并运行我的应用程序时,我从 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.properties
的 gradle.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/