gpt4 book ai didi

android - React Native Gradle 失败并显示 `java.lang.NullPointerException (no error message)`

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:21 31 4
gpt4 key购买 nike

问题

在一个全新的 React Native 项目(使用 create-react-native-app 创建)上,gradle 构建失败。

输出

--调试

$ cd android/
$ ./gradlew build --debug

给出这个输出(截断到错误点)

16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager]      InputStream: OriginalStream{jarFiles=[], folders=[], scopes=[SUB_PROJECTS], contentTypes=[CLASSES], dependencies=[prepareDebugDependencies, build dependencies configuration ':app:_debugApk' all dependencies]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] InputStream: OriginalStream{jarFiles=[], folders=[], scopes=[SUB_PROJECTS_LOCAL_DEPS], contentTypes=[CLASSES], dependencies=[prepareDebugDependencies, build dependencies configuration ':app:_debugApk' all dependencies]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] InputStream: OriginalStream{jarFiles=[], folders=[/Users/noel/w/crna-test/android/app/build/intermediates/classes/debug], scopes=[PROJECT], contentTypes=[CLASSES], dependencies=[compileDebugJavaWithJavac]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] OutputStream: IntermediateStream{rootLocation=/Users/noel/w/crna-test/android/app/build/intermediates/transforms/dex/debug, scopes=[PROJECT, PROJECT_LOCAL_DEPS, SUB_PROJECTS, SUB_PROJECTS_LOCAL_DEPS, EXTERNAL_LIBRARIES], contentTypes=[DEX], dependencies=[transformClassesWithDexForDebug]}
16:17:09.778 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project :app - Registering model element 'tasks.transformClassesWithDexForDebug' (hidden = false)
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter]
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter]
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred configuring project ':app'.
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] > java.lang.NullPointerException (no error message)
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter]
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
16:17:09.793 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
16:17:09.795 [LIFECYCLE] [org.gradle.BuildResultLogger]
16:17:09.795 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
16:17:09.795 [LIFECYCLE] [org.gradle.BuildResultLogger]
16:17:09.795 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 6.915 secs

--堆栈跟踪

堆栈跟踪是

$ ./gradlew build --stacktrace

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:74)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:540)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:93)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:124)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:121)
at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:99)
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:48)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:239)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:212)
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.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:205)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:55)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:36)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
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)
Caused by: java.lang.NullPointerException
at com.android.build.gradle.internal.ndk.DefaultNdkInfo.findTargetPlatformVersionOrLower(DefaultNdkInfo.java:167)
at com.android.build.gradle.internal.ndk.DefaultNdkInfo.findLatestPlatformVersion(DefaultNdkInfo.java:89)
at com.android.build.gradle.internal.ndk.NdkHandler.getPlatformVersion(NdkHandler.java:131)
at com.android.build.gradle.internal.ndk.NdkHandler.supports64Bits(NdkHandler.java:234)
at com.android.build.gradle.internal.ndk.NdkHandler.getSupportedAbis(NdkHandler.java:297)
at com.android.build.gradle.internal.transforms.StripDebugSymbolTransform.<init>(StripDebugSymbolTransform.java:86)
at com.android.build.gradle.internal.TaskManager.createStripNativeLibraryTask(TaskManager.java:1342)
at com.android.build.gradle.internal.ApplicationTaskManager.createTasksForVariantData(ApplicationTaskManager.java:289)
at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:485)
at com.android.build.gradle.internal.VariantManager$3.call(VariantManager.java:293)
at com.android.build.gradle.internal.VariantManager$3.call(VariantManager.java:290)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:120)
at com.android.build.gradle.internal.profile.SpanRecorders.record(SpanRecorders.java:44)
at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:286)
at com.android.build.gradle.BasePlugin$11.call(BasePlugin.java:688)
at com.android.build.gradle.BasePlugin$11.call(BasePlugin.java:685)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:120)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:683)
at com.android.build.gradle.BasePlugin$10.call(BasePlugin.java:608)
at com.android.build.gradle.BasePlugin$10.call(BasePlugin.java:605)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:120)
at com.android.build.gradle.BasePlugin.lambda$createTasks$1(BasePlugin.java:603)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:93)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:82)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:44)
at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
at org.gradle.internal.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)
... 44 more

.gradles

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}

应用

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.crnatest"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

环境

  • npm ls react-native-scripts: (空)
  • npm ls react-native: react-native@0.52.0
  • npm ls expo:(空)
  • node -v: v8.3.0
  • npm -v:5.6.0
  • yarn --version:0.21.3
  • 守望者版本: "version": "4.7.0"
  • 操作系统:macOS 10.13.3

可重现的演示

https://github.com/noelweichbrodt/crna-test

最佳答案

我在 Mac 而非 Windows 上构建时遇到了完全相同的问题(也使用 gradle 2.2.3)。我发现唯一有帮助的是将 gradle 版本降级到 2.1.2。不能 100% 确定为什么会这样,但确实如此。希望这对您有所帮助!

关于android - React Native Gradle 失败并显示 `java.lang.NullPointerException (no error message)`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49373513/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com