React Native - java.lang.RuntimeException:未找到 SDK 位置。在 local.properties 中使用 sdk.dir 定义位置
Posted
技术标签:
【中文标题】React Native - java.lang.RuntimeException:未找到 SDK 位置。在 local.properties 中使用 sdk.dir 定义位置【英文标题】:React Native - java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties 【发布时间】:2016-05-10 13:52:38 【问题描述】:React Native 入门。我确实安装了 android SDK、Java SDK 和 Android 依赖项。在我的终端上运行演示应用程序时收到以下错误。
我的 Galaxy 模拟器正在运行:
~ emulator @galaxy
HAXM is working and emulator runs in fast virt mode
emulator: UpdateChecker: skipped version check
现在我运行它:
~ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
at com.android.build.gradle.internal.SdkHandler.getAndCheckSdkFolder(SdkHandler.java:102)
at com.android.build.gradle.internal.SdkHandler.getSdkLoader(SdkHandler.java:112)
at com.android.build.gradle.internal.SdkHandler.initTarget(SdkHandler.java:86)
at com.android.build.gradle.BasePlugin.ensureTargetSetup(BasePlugin.groovy:507)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.groovy:455)
at com.android.build.gradle.BasePlugin$_createTasks_closure13_closure17.doCall(BasePlugin.groovy:415)
at com.android.build.gradle.BasePlugin$_createTasks_closure13_closure17.doCall(BasePlugin.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:292)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1015)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at com.android.build.gradle.internal.profile.SpanRecorders$2.call(SpanRecorders.groovy:52)
at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at com.android.build.gradle.internal.profile.SpanRecorders.record(SpanRecorders.groovy:54)
at com.android.build.gradle.BasePlugin$_createTasks_closure13.doCall(BasePlugin.groovy:414)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:292)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1015)
at groovy.lang.Closure.call(Closure.java:423)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:87)
at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy11.afterEvaluate(Unknown Source)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:67)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:487)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:85)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:50)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:27)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/jonathanbello/Documents/Personal-Projects/javascript/React-Native/WeatherApp/android/app/build.gradle' line: 102
* What went wrong:
A problem occurred evaluating project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.565 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
系统: - OSX优胜美地 - 节点 v 5.5
【问题讨论】:
这里回答了同样的问题:SDK location : *** 【参考方案1】:在 Android Studio 中:文件 -> 项目结构 -> Android SDK 位置
复制 Android SDK 路径
-
在您的 Project_Name -> Android -> 创建文件 local.properties
打开 local.properties。
写入 sdk.dir=/Users/Ashok/Library/Android/sdk
保存。
从您的项目根目录
react-native run-android
。
【讨论】:
我傻了,把 local.properties 文件放在根文件夹里,但是放在 Android 文件夹里。这可能就是我遇到同样错误的原因。 @Ashok.... Daaamn,这应该是 facebook 入门教程的一部分。非常感谢!【参考方案2】:以下是我如何在 Mac OSX 上让 react-native 与 Android 一起工作:
-
下载android studio并通过它更新android sdk,
https://developer.android.com/studio/index.html#downloads
在.base_profile
中添加路径
export ANDROID_HOME=/Users/UserName/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
将local.properties
文件放入project_name/android/
文件夹内。
编辑local.properties
,然后在其中添加sdk.dir=/Users/UserName/Library/Android/sdk
。
运行android
命令更新所需的软件包。
对于 RN 0.32,它的
运行android studio或android avd
命令打开模拟器
react-native run-android
在安卓中看到应用红屏后,react-native start
触发桥接服务器
【讨论】:
【参考方案3】:如果您使用的是 Android Studio,请按照以下步骤操作。
转到文件 > 项目结构 > 在 SDK 位置选项卡中添加“位置路径”,然后重试。【讨论】:
我没有使用Android Studio,但是下载了。我无法点击项目结构。【参考方案4】:在没有 android studio 的 Linux 中:
首先检查:您已经下载并解压了 android SDK 并运行了 android 命令来安装实际的开发 SDK?
在构建和运行时仍然找不到。那么问题可能是文件 local.properties 需要与 gradle stuff 位于同一目录中,以便 gradle 在构建和运行 adb 时找到它。
对于我使用的项目,我需要将 local.properties 文件放入 Myprojectname/android/ 文件夹,它开始工作。
由于我已将 SDK 解压缩到下载,因此我在文件中的路径是:sdk.dir=/home/USER/Downloads/android-sdk-linux
【讨论】:
【参考方案5】:将 android studio 路径添加到您的环境变量中
nano ~/.bash_profile
添加以下行:
export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
【讨论】:
我已经完成了所有这些,甚至创建了 local.properies 文件但仍然无法正常工作。以上是关于React Native - java.lang.RuntimeException:未找到 SDK 位置。在 local.properties 中使用 sdk.dir 定义位置的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.ClassNotFoundException:在路径上找不到类“.MainActivity”:DexPathList react-native [重复]
在 Android ICS 上编译 react-native fork: java.lang.NoClassDefFoundError: com/facebook/react/uimanager/Re
react native navigation: android app crash (java.lang.IllegalArgumentException: You need to use a Th
React Native - java.lang.RuntimeException:未找到 SDK 位置。在 local.properties 中使用 sdk.dir 定义位置
React-native Exception in thread "main" java.lang.RuntimeException: gradle-2.14.1-all.zip(
React-native Exception in thread "main" java.lang.RuntimeException: gradle-2.14.1-all.zip(