当前位置: 首页 > 知识库问答 >
问题:

React native-java.lang.RuntimeException:未找到SDK位置。在local.properties中使用sdk.dir定义位置

澹台岳
2023-03-14

开始使用React Native。我确实安装了Android SDK、Java SDK和Android依赖项。在我的终端上运行演示应用程序时,我收到以下错误。

~ 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 Yosemite-Node v 5.5

共有1个答案

商和雅
2023-03-14

在Android Studio中:文件->项目结构->Android SDK位置

  1. 在您的Project_Name中->Android->创建文件local.properties
  2. 打开local.properties。
  3. 写入sdk.dir=/users/ashok/library/android/sdk
  4. 保存。
  5. 从项目根目录React-native run-android中。
 类似资料:
  • 我试图使用GraphQL和Apollo Android客户端运行这个示例项目:https://github.com/apollographQL/apollo-android/tree/master/apollo-sample 我是Android studio的新手,以下是我目前所做的: 在我的机器(mac)上安装了Android Studio 克隆完整Apollo Android Repo 启动A

  • 我克隆了一个Android项目: 当我试图用android studio打开app文件夹以开始使用该项目时,我发现Gradle“app”项目刷新失败,错误:未找到SDK位置。使用sdk定义位置。本地目录。属性文件或使用ANDROID\u HOME环境变量。问题是,SDK位置已在local.properties中设置: 这与我在这台机器上使用的其他android项目中的位置相同。那么,为什么我会出现

  • 我最近创建了一个新的本地repo,并从我们的远程存储库中提取了一些代码。 当我打开项目时,我在控制台中收到一条消息: 我按照这里的说明设置环境变量(Im in a Mac),并检查了我的local.properties: 所以,这两件事都解决了,我仍然得到这个错误。我已经搜索过了,但是没有一个解决方案对我有效。 有什么帮助吗?非常感谢。 编辑: 这只发生在一个项目中。其余的项目运行良好。

  • 我正在尝试将我的android项目从Eclipse迁移到MAC中的android Studio v1.0.1 如果我创建一个新项目,一切正常,但如果我从Eclipse导入一个项目,则会出现以下错误: 错误:配置项目“MyProject”时出现问题。未找到SDK位置。使用sdk定义位置。本地目录。属性文件或使用ANDROID_HOME环境变量。 我的local.properties文件已经有了SDK

  • 我正在使用不同的方式构建应用程序,两种工作,但一种失败。 方法:1(工作) 方法:2(工作) 在Android Studio中打开模块,之后,选择 在这种情况下,我能够构建应用程序包和APK文件。 方法:3(不工作) 我得到了这个错误: 失败:生成失败,出现异常。*问题:配置根项目“android_intent”时出现问题。 未找到SDK位置。用sdk定义位置。在当地。属性文件或使用ANDROID

  • 所以我在Android Studio中运行Gradle时遇到了这个错误。问题是文件已存在,并且包含正确的数据。此外,我的电脑上还有其他项目与本地项目完全相同。属性内容,它们工作正常。我从Github下载的一个示例出现了这个错误。以下是该示例的链接。 完全错误: 错误:(17,0)找不到SDK位置。使用local.properties文件中的sdk.dir或ANDROID_HOME环境变量定义位置。