React Native android 常见错误和解决方法

邱秋8月前 23:19

Could not determine java version from '11.0.1'.

更新gradle即可,可参考gradle 版本更新,或者JDK降级到 8,请参考**Mac安装和卸载Java JDK**

Cannot add task 'wrapper' as a task with that name already exists.

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'    
    distributionUrl = distributionUrl.replace("bin", "all")
}
//修改为
wrapper {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

Failed to install the following Android SDK packages as some licences have not been accepted.

cd /Users/你的用户名/Library/Android/sdk
cd tools/bin
// 以上三行是进入到自己到sdk目录文件夹下

sudo ./sdkmanager --licenses //执行这句才是关键,它会提示你去允许认证

//然后命令会提醒你确定y/n(accept lincense),一路y下去便可以了。
//假如看到以下
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

1.点击 File > Settings(在 Mac 中,点击 Android Studio > Preferences),打开 Preferences 窗口。
2.在左侧面板中,点击 Appearance & Behavior > System Settings > Updates。
3.确保已选中 Automatically check for updates,然后从下拉列表中选择一个渠道(见图 1)。
4.点击 Apply 或 OK。

大概意思就是你把Android Studio 更新到最新版本就行了.  点那个check now ,直接更新

Could not install the app on the device, read the error above for details.

  • create (or edit) ~/.bashrc
  • export ANDROID_HOME=/Users/你的用户名/Library/Android/sdk
  • export PATH=${PATH}:${ANDROID_HOME}/tools
  • chmod 755 android/gradlew

org.gradle.api.resources.ResourceException: Could not get resource

Mac中,点击Android Studio>Preferences),打开Preferences窗口。Build,Execution,Deployment=>Gradle=>Android Studio,勾选Enable embedded Maven repository

Could not resolve all files for configuration ':app:releaseCompileClasspath

1.修改android/build.gradle中google()方法的位置,见下方代码注释;

allprojects {
    repositories {
        google() // new 移到这里来
        mavenLocal()
        jcenter()
        maven {url "https://jitpack.io"}
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {url "https://maven.google.com"}
        // google() // old
    }
}

2.如果还不行,就升级gradle版本到4.10.1

Failed to capture snapshot of input files for task ':app:javaPreCompileDebug

appbuild

android {
  defaultConfig {
    //添加如下配置就OK了
    javaCompileOptions { 
      annotationProcessorOptions { includeCompileClasspath = true } 
    }
  }
}

Execution failed for task ':react-native-yunpeng-alipay:compileDebugJavaWithJavac'.

打开ReactNative根目录下的node_modules文件夹 找到react-native-yunpeng-alipay文件夹并打开 依次打开目录: android -> src -> main -> java -> com -> yunpeng -> alipay -> AlipayPackage.java

注释调这一行
//    @Override
//    public List<Class<? extends JavaScriptModule>> createJSModules() {
//        return Collections.emptyList();
//    }

Execution failed for task 'xxx:verifyReleaseResources'

0.57版本打包错误,SDK版本不匹配问题

  • 1.首先在node_modules中找到报错的包里面的build.gradle,比如我这个就是\node_modules\react-native-version-number\android\build.gradle;
  • 2.修改这个build.gradle,使其与android/build.gradle(也可能是android/app/build.gradle)里面的SDK版本保持一致;
  • 3.将build.gradle里的compile改为implementation,因为compile已过时。
android {
    compileSdkVersion 27 // 23 -> 27
    buildToolsVersion "27.0.3" // 23.0.1 -> 27.0.3
 
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26 // 22 -> 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    lintOptions {
       warning 'InvalidPackage'
    }
}
dependencies {
    implementation 'com.facebook.react:react-native:+' // compile -> implementation
}

Execution failed for task ':app:processDebugManifest'

已经提示了合并错误
Manifest merger failed with multiple errors, see logs
打开AndroidMainifest.xml=> 点底部的Merged Mainfest=> 看到右边的合并错误, 点进去, 注释掉重复的就可以了 http://yifeng.studio/2017/07/09/android-manifest-merge-conflict/

Execution failed for task ':appbase:installDebugAndroidTest'.

快速定义错误,进入终端输入
./gradlew compileDebugJavaWithJavac --stacktrace
看看哪里报错了,修正即可

Could not resolve com.squareup.okhttp3:okhttp:3.9.1.

mavenCentral()
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }

本文将持续更新...

本文于8月前 23:19发布在code分类下,当前已被围观673次

相关标签:react,javascript,react-native,andriod,

永久地址:https://www.chuchur.com/article/react-native-android-error

版权声明: 自由转载-署名-非商业性使用