Mos*_*ses 27 android gradle android-studio android-gradle-plugin react-native
我有以下课程
import com.android.annotations.NonNullByDefault;
@NonNullByDefault
public final class Log {
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的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'
}
Run Code Online (Sandbox Code Playgroud)
在Android Studio中,我的课程没有警告
但是,当我尝试构建和运行我的应用程序时,我从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
Run Code Online (Sandbox Code Playgroud)
Pav*_*rre 55
要自动修复React Native的所有android至androidx问题,(前提条件npx)
将以下两个标记添加到位于ProjectFolder / android / gradle.properties的gradle.properties文件中的true
android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
执行
npm install --save-dev jetifier
npx jetify
npx react-native run-android
Run Code Online (Sandbox Code Playgroud)
在package.json中,将以下内容添加到脚本中
"postinstall" : "npx jetify"
Run Code Online (Sandbox Code Playgroud)
更多信息请参见https://github.com/mikehardy/jetifier
更新: 现在内置于本机0.60中。如果您迁移到本机0.60,则不需要此步骤。- https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support
Sar*_*hal 17
androidx.appcompat:appcompat:1.0.2在gradle中使用实现,然后
更改import android.support.annotation.Nullable;
为import androidx.annotation.NonNull;类导入
use*_*776 14
I had similar issues when migrating to androidx.
If by adding the below two lines to gradle.properties did not solve the issue
android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
Then try
If you still run into issues with migration then manually try to replace the libraries which are causing the issue.
For example
If you have an issue with android.support.annotation.NonNull change it to androidx.annotation.NonNull as indicated in the below class mappings table.
rib*_*bit 13
就我而言,我不得不使用
import androidx.annotation...
Run Code Online (Sandbox Code Playgroud)
代替
import android.annotation...
Run Code Online (Sandbox Code Playgroud)
我迁移到 AndroidX 并忘记更改它。
Beh*_*z.M 11
Open gradle.properties and use following code:
android.useAndroidX=false
android.enableJetifier=false
Run Code Online (Sandbox Code Playgroud)
or U can use these dependencies too:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.annotation:annotation:1.0.2'
Run Code Online (Sandbox Code Playgroud)
小智 9
对于 Ionic,试试这个:
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
Run Code Online (Sandbox Code Playgroud)
出现错误是因为该应用程序未使用 androidX,但这些插件解决了错误。
只需安装(它会自动修复)
npm install --save-dev jetifier <--------avoid if aleardy installed start from below lines
npx jetify
Run Code Online (Sandbox Code Playgroud)
然后运行
npx cap sync
Run Code Online (Sandbox Code Playgroud)
最后
npx react-native run-android
Run Code Online (Sandbox Code Playgroud)
注释来自support's library打包在android.support.annotation.
作为另一个选项,您可以使用@NonNull注释来表示参数、字段或方法返回值永远不能为空。
它是从进口的import android.support.annotation.NonNull;
| 归档时间: |
|
| 查看次数: |
45894 次 |
| 最近记录: |