iro*_*dsd 6 android react-native
我不得不完全重写这个问题。
我有一个React Native Android应用程序。当我使用构建apk
文件时./gradlew assembleRelease -x bundleReleaseJsAndAssets
,它运行良好,但此后它完全停止编译。甚至react-native run-android
不再工作了。
我到目前为止发现的是:首先,错误是这样的
Task :app:processDebugResources FAILED
resource android:attr/fontVariationSettings not found.
resource android:attr/ttcIndex not found.
Run Code Online (Sandbox Code Playgroud)
如果我将这些行添加到中gradle.properties
,
android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
错误发生变化。现在就是这个
Task :@JWWon_react-native-universal-pedometer:compileDebugJavaWithJavac FAILED
error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
cannot find symbol
private void sendPedometerUpdateEvent(@Nullable WritableMap params) {
^
symbol: class Nullable
location: class BMDPedometerModule
Run Code Online (Sandbox Code Playgroud)
问题不在于库。如果我从项目中删除它,它将开始抱怨另一个项目。要使其编译,我必须删除7个库。一个例子:
Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED
error: package android.support.v4.net does not exist
import android.support.v4.net.ConnectivityManagerCompat;
error: cannot find symbol
promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()));
^
symbol: variable ConnectivityManagerCompat
location: class ConnectivityReceiver
2 errors
Run Code Online (Sandbox Code Playgroud)
然后如果我删除另一个,则会发生这种情况:
Task :react-native-camera-kit:compileDebugJavaWithJavac FAILED
package android.support.annotation does not exist
import android.support.annotation.ColorInt;
^
package android.support.annotation does not exist
import android.support.annotation.IntRange;
^
...
92 errors
Run Code Online (Sandbox Code Playgroud)
因此,如果我从项目中删除7个库,它将进行编译。他们是:
react-native-camera-kit
@react-native-community_netinfo
react-native-push-notification
react-native-sensors
@JWWon_react-native-universal-pedometer
react-native-keep-awake
react-native-toast-native
没有它们,它可以完美地编译。因此,有一个更大的问题使它无法正常工作。2天前,所有这些库都运行正常,没有问题。但是现在有些东西压垮了它。
小智 15
尝试使用喷射器
npm install --save-dev jetifier
或使用纱线,但将其安装在项目的本地而不是全局
npx jetify
或
npx jetify -w=1
-指定并行工作者的数量
npx react-native run-android
尝试使用 androidx
// build.gradle
implementation "androidx.annotation:annotation:1.1.0"
// where use it
import androidx.annotation.Nullable;
Run Code Online (Sandbox Code Playgroud)
更新:
如果其他库出错,也许你可以试试jetifier,我通过这个有用的问题知道它。
完整参考如下,希望有帮助:)
// android/build.gradle
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 24
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "1.0.0-beta01"
}
// app/build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "androidx.core:core:1.0.2"
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.appcompat:appcompat:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:0.59.9" // From node_modules
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我遇到了这个问题(AndroidX)几天,最后通过更新解决它react-native@0.59.9
,使用最新的android设置和magic jetifier。
allprojects {
repositories {
bla bla bla...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.+"
}
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') && !details.requested.name.contains('play-services-stats')) {
details.useVersion "12.+"
}
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') && details.requested.name.contains('play-services-stats')) {
details.useVersion "+"
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
在build.gradle中添加子项目(android)
dependencies {
...bla bla bla
implementation "com.google.android.gms:play-services-gcm:12.+"
Run Code Online (Sandbox Code Playgroud)
}
在build.gradle(android / app)中添加实现“ com.google.android.gms:play-services-gcm:12. +”
因此您无需迁移到Androidx
小智 6
我实际上发生了非常相似的事情,运行了它
npx jetify
Run Code Online (Sandbox Code Playgroud)
当我通过CI管道运行它时,它不起作用,并最终不得不添加
"scripts": {
...
"postinstall": "jetify"
}
Run Code Online (Sandbox Code Playgroud)
npm在管道中运行安装后,然后运行jetify转换为androidx并涵盖所有需要转换的库。
归档时间: |
|
查看次数: |
13526 次 |
最近记录: |