react-native run-android 问题(mac)

react-native run-android 一些问题
  • 问题1: error Failed to launch emulator. Reason: No emulators found as an output of emulator -list-avds.
    解决:
  1. 确保装了android sdk ,你需要能找到目录,比如在mac上
    cd 	~/Library/Android/sdk
    
    可以看到这些文件
    在这里插入图片描述
  2. 确保环境变量正确
 vim ~/.bash_profile  
 # 打开.bash_profile 文件,里面有以下这些环境变量导出.确保正确可以通过
# echo $ANDROID_HOME/tools 查看路径是否正确,如果报错请检查

export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH
  1. 如果以上都对,则 通过安装android-platform-tools
brew install android-platform-tools

以上三步可解决error Failed to launch emulator. Reason: No emulators found as an output of emulator -list-avds的问题

  • 问题2: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
    解决: 查看java jdk版本 ,终端输入java -version
    目标java jdk 版本要1.8以上去官网找1.8版本!
    这个是jdk下载地址,需要登录才能下载:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
    通常是jdk版本过低,可以参照以下进行安装,并配置
    https://blog.csdn.net/deliciousion/article/details/78046007
    配置好之后,问题解决

  • 问题3:

* What went wrong:
A problem occurred configuring root project 'proger'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.ow2.asm:asm:6.0.
     Required by:
         project : > com.android.tools.build:gradle:3.5.3
         project : > com.android.tools.build:gradle:3.5.3 > com.android.tools.build:builder:3.5.3

解决:

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.3.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

修改为以下,为buildscript添加上了这段maven编译地址

maven {
     url 'https://maven.google.com/'
     name 'Google'
      }
      

修改完后为:

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.3.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
  • 问题5:
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > org.gradle.api.file.ProjectLayout.directoryProperty(Lorg/gradle/api/provider/Provider;)Lorg/gradle/api/file/DirectoryProperty;

解决:
通过清除Gradle缓存

rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease

如果不能解决 ,尝试 方法2:

For everyone cloning that project, with Android studio 4, I needed to :

Change Android Gradle project version from 3.3.2 to 4.01 : https://stackoverflow.com/a/63206864

Error was Unable to find method 'org.gradle.api.file.ProjectLayout.directoryProperty(Lorg/gradle/api/provider/Provider;)Lorg/gradle/api/file/DirectoryProperty;'.

Create gradle.properties in root project folder with : android.useAndroidX=true

Error was This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.

注意 ⚠️ 千万要重装弄node_modules


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值