旧项目Android Studio 编译适配-NDK issue
问题点记录
旧的项目 在Android Studio新版本编译中遇到以下问题。 流水式总结记录一下
NDK getPlatformVersion -> NULL
编译一开始 遇见的问题log如下
Caused by: java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877)
at com.android.build.gradle.internal.ndk.NdkHandler.getPlatformVersion(NdkHandler.java:167)
at com.android.build.gradle.internal.ndk.NdkHandler.supports64Bits(NdkHandler.java:340)
at com.android.build.gradle.internal.ndk.NdkHandler.getSupportedAbis(NdkHandler.java:412)
at com.android.build.gradle.tasks.ExternalNativeJsonGenerator.create(ExternalNativeJsonGenerator.java:626)
at com.android.build.gradle.internal.TaskManager.createExternalNativeBuildJsonGenerators(TaskManager.java:1552)
at com.android.build.gradle.internal.ApplicationTaskManager.createTasksForVariantScope(ApplicationTaskManager.java:166)
at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:491)
at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:365)
解决方案 1
local.properties 标明具体的ndk版本
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Nov 30 18:08:21 CST 2021
sdk.dir=C\:\\Android\\sdk
ndk.dir=C\:\\Android\\sdk\\ndk\\21.4.7075529
Invalid revision cmake 3.18.1
继续编译 遇到如下问题
Caused by: java.lang.NumberFormatException: Invalid revision: 3.18.1-g262b901-dirty
at com.android.repository.Revision.parseRevision(Revision.java:133)
at com.android.repository.Revision.parseRevision(Revision.java:155)
at com.android.build.gradle.external.cmake.CmakeUtils.getVersion(CmakeUtils.java:51)
at com.android.build.gradle.tasks.ExternalNativeJsonGenerator.createCmakeExternalNativeJsonGenerator(ExternalNativeJsonGenerator.java:867)
at com.android.build.gradle.tasks.ExternalNativeJsonGenerator.create(ExternalNativeJsonGenerator.java:794)
at com.android.build.gradle.internal.TaskManager.createExternalNativeBuildJsonGenerators(TaskManager.java:1711)
at com.android.build.gradle.internal.LibraryTaskManager.lambda$createTasksForVariantScope$11(LibraryTaskManager.java:248)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
at com.android.build.gradle.internal.LibraryTaskManager.createTasksForVariantScope(LibraryTaskManager.java:243)
at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:530)
at com.android.build.gradle.internal.VariantManager.lambda$createAndroidTasks$1(VariantManager.java:352)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:348)
at com.android.build.gradle.BasePlugin.lambda$createAndroidTasks$6(BasePlugin.java:751)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:746)
at com.android.build.gradle.BasePlugin.lambda$null$4(BasePlugin.java:652)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
at com.android.build.gradle.BasePlugin.lambda$createTasks$5(BasePlugin.java:648)
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.$Proxy31.afterEvaluate(Unknown Source)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:76)
... 82 more
解决方案 2
通过sdk manager 将Cmake 3.18.1 卸载
CMAKE_MAKE_PROGRAM is not set
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
解决方案 3
升级gradle版本 不低于3.3.0
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
//classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
总结
遇到这种问题 如果项目没有标明使用的Android Studio版本 只能认倒霉。逐一排查
|