React-Native 异常与解决集

施永宁
2023-12-01

1:

FAILURE: Build failed with an exception.

* What went wrong:
Failed to capture snapshot of output files for task ':app:processDebugResources' property 'sourceOutputDir' during up-to-date check.
> Could not read path 'I:\ReactProject\Project\ReactNativeDemo\android\app\build\generated\source\r\debug\android\arch\lifecycle\livedata\core'.

解决方法:cd android 

gradlew clean

2:react-native-picker package android.support.annotation does not exist import android.support.annotation.Nullable

解决方法:import android.support.annotation.Nullable; ——>import androidx.annotation.Nullable;

 

3:react-native-picker打包异常

> Task :react-native-picker:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-picker:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  I:\ReactProject\Project\a9app\amor\node_modules\react-native-picker\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRa
dius not found.
  I:\ReactProject\Project\a9app\amor\node_modules\react-native-picker\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerR
adius not found.
  I:\ReactProject\Project\a9app\amor\node_modules\react-native-picker\android\build\intermediates\res\merged\release\values\values.xml:2727: error: resource android:attr/fontVariationSettin
gs not found.
  I:\ReactProject\Project\a9app\amor\node_modules\react-native-picker\android\build\intermediates\res\merged\release\values\values.xml:2728: error: resource android:attr/ttcIndex not found.
  error: failed linking references.

解决方法:

打开文件:node_modules/react-native-picker/android/build.gradle

修改为:

android {
    compileSdkVersion 28
    //buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
}

4:错误: 程序包android.support.v4.content不存在

解决方法:

android/app/build.gradle中添加

dependencies{
    implementation 'com.android.support:support-v4:22.2.0'
}

5:Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

 Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

 解决方法:

android/app/build.gradle中添加

 defaultConfig {
        ...
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }

6:Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

问题:

   gradle版本过低    

解决方法:

到项目的 android/gradle/wrapper/gradle-wrapper.properties 

 将   distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

 改为:distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

保存后重新run-android,如果在下载gradle超时失败时建议使用AndroidStudio进行加载

7:应用安装后闪退捕捉异常为:couldn't find DSO to load: libfbjni.so result:

解决方法:

清空缓存然后再打包安装或者安装调试

cd ./android

gradlew clean

8:react-native-fast-image 打包时异常

Execution failed for task ':react-native-fast-image:mergeReleaseResources'.
Could not resolve all files for configuration ':react-native-fast-image:releaseRuntimeClasspath'.
   > Could not resolve com.facebook.react:react-native:+.
     Required by:
         project :react-native-fast-image
      > Failed to list versions for com.facebook.react:react-native.
         > Unable to load Maven meta-data from https://maven.google.com/com/facebook/react/react-native/maven-metadata.xml.
            > Could not get resource 'https://maven.google.com/com/facebook/react/react-native/maven-metadata.xml'.
               > Could not GET 'https://maven.google.com/com/facebook/react/react-native/maven-metadata.xml'.
                  > Connect to maven.google.com:443 [maven.google.com/172.217.24.14] failed: connect timed out

解决方法,修改后clean之后再打包


repositories {
    mavenCentral()
    google()
    maven {
        url "https://maven.google.com"
    }
}
改为
repositories {
    mavenCentral()
    google()
    maven {
        url "http://maven.aliyun.com/nexus/content/groups/public/"
    }
}

 

 类似资料: