cocos creator 编译android失败

  • Creator 版本:

  • 目标平台:

  • 详细报错信息,包含调用堆栈:

  • 重现方式:

  • 之前哪个版本是正常的 :

  • 手机型号 :

  • 手机浏览器 :

  • 编辑器操作系统 :

  • 编辑器之前是否有其它报错 :

  • 出现概率:

  • 额外线索:

2.3版本的

先使用android studio打开,看下报错信息是否一样?

想知道可能是什么的问题

在AS中是一样的错误

碰到一样的问题,请问请问解决了吗?

可以试试提高下Android的 API版本

这个模块是给Google Instant使用的,你也可以直接屏蔽对应模块,删除红色圈圈部分

Starting Gradle Daemon…
Gradle Daemon started in 2 s 579 ms

Configure project :libcocos2dx
NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Configure project :TestProject
NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ‘:TestProject’.

java.lang.NullPointerException (no error message)

  • Try:
    Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is:
    org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ‘:TestProject’.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:79)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:73)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:54)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:200)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.run(LifecycleProjectEvaluator.java:110)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:68)
    at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:687)
    at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:140)
    at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:62)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:41)
    at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:274)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:182)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:141)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:124)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:77)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:74)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:154)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:38)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:96)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:74)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner.run(ClientProvidedPhasedActionRunner.java:61)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.run(RunAsBuildOperationBuildActionRunner.java:50)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:44)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:79)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:44)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:62)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:34)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:59)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:31)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:46)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:81)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787)
    at com.android.build.gradle.internal.ndk.NdkHandler.getPlatformVersion(NdkHandler.java:159)
    at com.android.build.gradle.internal.ndk.NdkHandler.supports64Bits(NdkHandler.java:332)
    at com.android.build.gradle.internal.ndk.NdkHandler.getSupportedAbis(NdkHandler.java:404)
    at com.android.build.gradle.tasks.ExternalNativeJsonGenerator.create(ExternalNativeJsonGenerator.java:583)
    at com.android.build.gradle.internal.TaskManager.createExternalNativeBuildJsonGenerators(TaskManager.java:1602)
    at com.android.build.gradle.internal.ApplicationTaskManager.createTasksForVariantScope(ApplicationTaskManager.java:167)
    at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:633)
    at com.android.build.gradle.internal.VariantManager.lambda$createAndroidTasks$1(VariantManager.java:381)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
    at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:377)
    at com.android.build.gradle.BasePlugin.lambda$createAndroidTasks$6(BasePlugin.java:800)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
    at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:795)
    at com.android.build.gradle.BasePlugin.lambda$null$4(BasePlugin.java:690)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
    at com.android.build.gradle.BasePlugin.lambda$createTasks$5(BasePlugin.java:686)
    at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction$1$1.run(DefaultListenerBuildOperationDecorator.java:157)
    at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.reapply(DefaultUserCodeApplicationContext.java:58)
    at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction$1.run(DefaultListenerBuildOperationDecorator.java:154)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction.execute(DefaultListenerBuildOperationDecorator.java:151)
    at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:91)
    at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:80)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy36.afterEvaluate(Unknown Source)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate$1.execute(LifecycleProjectEvaluator.java:187)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate$1.execute(LifecycleProjectEvaluator.java:184)
    at org.gradle.api.internal.project.DefaultProject.stepEvaluationListener(DefaultProject.java:1418)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:193)
    … 92 more

  • Get more help at https://help.gradle.org

BUILD FAILED in 15s

用了30的api,也删除了,’:game’, ‘:instantapp’ 还是一样的问题,以上是构建成功后,导入Android Studio后报的错误

编译模式:release
使用 Android Studio 工程:D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio
正在生成 apk 文件…
正在执行:’“D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio\gradlew.bat” --parallel --info assembleRelease’

Initialized native services in: C:\Users\Administrator.gradle\native
Found daemon DaemonInfo{pid=28480, address=[37f5cbd4-ceeb-4674-81e1-f6e085b89c9a port:63050, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], state=Idle, lastBusy=1609407643509, context=DefaultDaemonContext[uid=b7f6ab1b-b9f9-4c70-aa01-00817625ffe7,javaHome=D:\Program Files\Android\Android Studio\jre,daemonRegistryDir=C:\Users\Administrator.gradle\daemon,pid=28480,idleTimeout=10800000,daemonOpts=-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]} however its context does not match the desired criteria.
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=D:\Program Files\Java\jdk1.8.0_172,daemonRegistryDir=C:\Users\Administrator.gradle\daemon,pid=20160,idleTimeout=null,daemonOpts=-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
Actual: DefaultDaemonContext[uid=b7f6ab1b-b9f9-4c70-aa01-00817625ffe7,javaHome=D:\Program Files\Android\Android Studio\jre,daemonRegistryDir=C:\Users\Administrator.gradle\daemon,pid=28480,idleTimeout=10800000,daemonOpts=-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]

Looking for a different daemon…
The client will now receive all logging from the daemon (pid: 28632). The daemon log file: C:\Users\Administrator.gradle\daemon\4.10.3\daemon-28632.out.log
Starting 2nd build in daemon [uptime: 8 mins 19.256 secs, performance: 96%, no major garbage collections]
Using 4 worker leases.
Invalidating in-memory cache of D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio.gradle\4.10.3\fileHashes\fileHashes.bin
Starting Build
Invalidating in-memory cache of C:\Users\Administrator.gradle\caches\4.10.3\fileHashes\fileHashes.bin
Invalidating in-memory cache of C:\Users\Administrator.gradle\caches\4.10.3\fileHashes\resourceHashesCache.bin
Settings evaluated using settings file ‘D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio\settings.gradle’.
Projects loaded. Root project using build file ‘D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio\build.gradle’.
Included projects: [root project ‘proj.android-studio’, project ‘:libcocos2dx’, project ‘:TestProject’]
Parallel execution is an incubating feature.

Configure project :
Evaluating root project ‘proj.android-studio’ using build file ‘D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio\build.gradle’.
Invalidating in-memory cache of C:\Users\Administrator.gradle\caches\journal-1\file-access.bin

Configure project :libcocos2dx
Evaluating project ‘:libcocos2dx’ using build file ‘D:\cocosProject\TestProject\build\jsb-default\frameworks\cocos2d-x\cocos\platform\android\libcocos2dx\build.gradle’.
Creating configuration androidTestUtil
Creating configuration compile
Creating configuration publish
Creating configuration provided
Creating configuration api
Creating configuration implementation
Creating configuration runtimeOnly
Creating configuration compileOnly
Creating configuration wearApp
Creating configuration annotationProcessor
Creating configuration androidTestCompile
Creating configuration androidTestPublish
Creating configuration androidTestProvided
Creating configuration androidTestApi
Creating configuration androidTestImplementation
Creating configuration androidTestRuntimeOnly
Creating configuration androidTestCompileOnly
Creating configuration androidTestWearApp
Creating configuration androidTestAnnotationProcessor
Creating configuration testCompile
Creating configuration testPublish
Creating configuration testProvided
Creating configuration testApi
Creating configuration testImplementation
Creating configuration testRuntimeOnly
Creating configuration testCompileOnly
Creating configuration testWearApp
Creating configuration testAnnotationProcessor
NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Creating configuration debugCompile
Creating configuration debugPublish
Creating configuration debugProvided
Creating configuration debugApi
Creating configuration debugImplementation
Creating configuration debugRuntimeOnly
Creating configuration debugCompileOnly
Creating configuration debugWearApp
Creating configuration debugAnnotationProcessor
Creating configuration androidTestDebugCompile
Creating configuration androidTestDebugPublish
Creating configuration androidTestDebugProvided
Creating configuration androidTestDebugApi
Creating configuration androidTestDebugImplementation
Creating configuration androidTestDebugRuntimeOnly
Creating configuration androidTestDebugCompileOnly
Creating configuration androidTestDebugWearApp
Creating configuration androidTestDebugAnnotationProcessor
Creating configuration testDebugCompile
Creating configuration testDebugPublish
Creating configuration testDebugProvided
Creating configuration testDebugApi
Creating configuration testDebugImplementation
Creating configuration testDebugRuntimeOnly
Creating configuration testDebugCompileOnly
Creating configuration testDebugWearApp
Creating configuration testDebugAnnotationProcessor
Creating configuration releaseCompile
Creating configuration releasePublish
Creating configuration releaseProvided
Creating configuration releaseApi
Creating configuration releaseImplementation
Creating configuration releaseRuntimeOnly
Creating configuration releaseCompileOnly
Creating configuration releaseWearApp
Creating configuration releaseAnnotationProcessor
Creating configuration testReleaseCompile
Creating configuration testReleasePublish
Creating configuration testReleaseProvided
Creating configuration testReleaseApi
Creating configuration testReleaseImplementation
Creating configuration testReleaseRuntimeOnly
Creating configuration testReleaseCompileOnly
Creating configuration testReleaseWearApp
Creating configuration testReleaseAnnotationProcessor
Parsing the SDK, no caching allowed
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\23.0.3\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\26.0.2\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\27.0.3\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\28.0.3\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\emulator\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\extras\android\m2repository\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\extras\google\m2repository\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\extras\m2repository\com\android\support\constraint\constraint-layout-solver\1.0.2\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\extras\m2repository\com\android\support\constraint\constraint-layout\1.0.2\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\19.2.5345600\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\22.0.7026061\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\patcher\v4\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-23\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-26\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-27\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-28\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-29\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-30\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-23\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-26\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-27\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-28\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-29\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\sources\android-30\package.xml
Parsing C:\Users\Administrator\AppData\Local\Android\Sdk\tools\package.xml
SDK initialized in 175 ms
Using incremental javac compilation for :libcocos2dx debug.
Using incremental javac compilation for :libcocos2dx debugUnitTest.
Using incremental javac compilation for :libcocos2dx release.
Using incremental javac compilation for :libcocos2dx releaseUnitTest.
Using incremental javac compilation for :libcocos2dx debugAndroidTest.

Configure project :TestProject
Evaluating project ‘:TestProject’ using build file ‘D:\cocosProject\TestProject\build\jsb-default\frameworks\runtime-src\proj.android-studio\app\build.gradle’.
Creating configuration androidTestUtil
Creating configuration compile
Creating configuration apk
Creating configuration provided
Creating configuration api
Creating configuration implementation
Creating configuration runtimeOnly
Creating configuration compileOnly
Creating configuration wearApp
Creating configuration annotationProcessor
Creating configuration androidTestCompile
Creating configuration androidTestApk
Creating configuration androidTestProvided
Creating configuration androidTestApi
Creating configuration androidTestImplementation
Creating configuration androidTestRuntimeOnly
Creating configuration androidTestCompileOnly
Creating configuration androidTestWearApp
Creating configuration androidTestAnnotationProcessor
Creating configuration testCompile
Creating configuration testApk
Creating configuration testProvided
Creating configuration testApi
Creating configuration testImplementation
Creating configuration testRuntimeOnly
Creating configuration testCompileOnly
Creating configuration testWearApp
Creating configuration testAnnotationProcessor
NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Creating configuration debugCompile
Creating configuration debugApk
Creating configuration debugProvided
Creating configuration debugApi
Creating configuration debugImplementation
Creating configuration debugRuntimeOnly
Creating configuration debugCompileOnly
Creating configuration debugWearApp
Creating configuration debugAnnotationProcessor
Creating configuration androidTestDebugCompile
Creating configuration androidTestDebugApk
Creating configuration androidTestDebugProvided
Creating configuration androidTestDebugApi
Creating configuration androidTestDebugImplementation
Creating configuration androidTestDebugRuntimeOnly
Creating configuration androidTestDebugCompileOnly
Creating configuration androidTestDebugWearApp
Creating configuration androidTestDebugAnnotationProcessor
Creating configuration testDebugCompile
Creating configuration testDebugApk
Creating configuration testDebugProvided
Creating configuration testDebugApi
Creating configuration testDebugImplementation
Creating configuration testDebugRuntimeOnly
Creating configuration testDebugCompileOnly
Creating configuration testDebugWearApp
Creating configuration testDebugAnnotationProcessor
Creating configuration releaseCompile
Creating configuration releaseApk
Creating configuration releaseProvided
Creating configuration releaseApi
Creating configuration releaseImplementation
Creating configuration releaseRuntimeOnly
Creating configuration releaseCompileOnly
Creating configuration releaseWearApp
Creating configuration releaseAnnotationProcessor
Creating configuration testReleaseCompile
Creating configuration testReleaseApk
Creating configuration testReleaseProvided
Creating configuration testReleaseApi
Creating configuration testReleaseImplementation
Creating configuration testReleaseRuntimeOnly
Creating configuration testReleaseCompileOnly
Creating configuration testReleaseWearApp
Creating configuration testReleaseAnnotationProcessor
Parsing the SDK, no caching allowed
SDK initialized in 3 ms

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ‘:TestProject’.

java.lang.NullPointerException (no error message)

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s
执行命令出错,返回值:1。

这是coscos编译时的日志。工程是一个空的工程,coscos版本为:2.3.1

问题已经解决,是NDK版本不匹配,先给出解决步骤:
1、清除..\AppData\Local\Android\Sdk\ndk-bundle下的所有内容,不管你之前版本是什么,既然已经出现打包错误就说明有问题。不放心的可以先备份。
2、去https://developer.android.google.cn/ndk/downloads/older_releases下载android-ndk-r17c-windows-x86_64.zip,解压后全部拷入ndk-bundle文件夹里
3、打开coscos删除之前构建的项目文件夹,重新进行构建。
4、打开Android Studio,通过Import Project导入构建好的proj.android-studio项目,然后打开项目时,右下角会弹出:Android Gradle Plugin is ready to update 切记,不要点update,我就是第一次的时候这里点了update,所以出现了之后各种各样的问题
5、然后选择菜单builder-Generate Signed Bundle / APK,然后选择下面那个“APK”打包即可。
6、如果builder菜单没有Generate Signed Bundle / APK,先选择菜单file-Sync Project with Gradle Files,通过后就可以了

几点注意的地方:
1、我之前一直使用的是coscos2.3.1,为了解决这个问题,我把coscos升级至2.4.3构建后,问题仍然存在,初步判断应该和coscos版本无关。
2、coscos构建完成,默认使用的是classpath ‘com.android.tools.build:gradle:3.2.0’和gradle-4.10.3-all.zip,这个不要修改,如果强行提升版本,Android Studio编译可以通过,但是打包还是会出现各种问题。
3、构建时选择Target API Level android-27以上都是可以的,27以下没有尝试。
4、Android\Sdk\ndk-bundle我之前第一次拷入了一个r19的版本,最后问题仍然存在,以为不是这个问题,所以这里又绕了很多弯路。之后实在没办法就尝试了r17版本,没想到居然可以了。r18我没有尝试。
5、Android Studio编译和打包时出现类似“A problem occurred configuring project’:game’”、“Failed to create parent directory”、“Could not resolve project :libcocos2dx.”、“No rule to make target `cocos2djs’”都是由于NDK版本不匹配的问题。
6、Android Studio导入时,会出现Android Gradle Plugin is ready to update,切记不要update,不要update,不要update。之前看到一个帖子说,前一天打包还好好的,第二天没有修改任何代码,但是打包就是出异常了,我觉得应该就是update了NDK。因为这个不一定是你coscos这个工程才会让你升级,当你打开别的工程时也会提示你要update,如果升级后,再回来打包coscos的工程就会出问题。
1609634162(1)

由于这个问题涉及到coccos creator、Android Studio、gradle、com.android.tools.build、NDK等工具和插件的整合问题,所以百度上其实没有一个完整的解决方法。今天留下这个帖子,希望为未来碰到这个问题的小伙伴提供一个解决方案。

不要用creator去编译APK,出错几率非常大。各种莫名其妙的报错。用Android studio

今天同样遇到这个问题,几次cocos 构建 编译正常,到了AS后就再也不行了,都是这里的坑