gpt4 book ai didi

即使在正确设置 abiFilters 之后,Android Studio 也会忽略 ndk-build 的 APP_ABI

转载 作者:行者123 更新时间:2023-12-03 05:32:59 30 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,该应用程序具有使用 ndk-build 构建的 native 库依赖项.反过来,该库取决于我添加到根目录 Android.mk 中的预构建静态库 (.a)如下。我打算只为 armeabi-v7a 构建和 arm64-v8a .

ifeq ($(TARGET_ARCH), arm)
LOCAL_SRC_FILES := lib/mylib_arm.a
else ifeq ($(TARGET_ARCH), arm64)
LOCAL_SRC_FILES := lib/mylib_arm64.a
else
$(error platform not supported!)
endif

当我尝试构建项目时,构建在任务 :app:externalNativeBuildCleanDebug 处失败,出现以下错误。
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:externalNativeBuildCleanDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.gradle.internal.UncheckedException: Build command failed.
Error while executing process /home/sourav/android/sdk/ndk/20.0.5594570/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/sourav/code/app/app/src/main/jni/Android.mk NDK_APPLICATION_MK=/home/sourav/code/app/app/src/main/jni/Application.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/sourav/code/app/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/sourav/code/app/app/build/intermediates/ndkBuild/debug/lib clean}

/home/sourav/code/app/app/src/main/jni/mylib/Android.mk:12: *** platform not supported!. Stop.

经过进一步检查,我发现正在调用构建,如下所示
/home/sourav/android/sdk/ndk/20.0.5594570/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/sourav/code/app/app/src/main/jni/Android.mk NDK_APPLICATION_MK=/home/sourav/code/app/app/src/main/jni/Application.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/sourav/code/app/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/sourav/code/app/app/build/intermediates/ndkBuild/debug/lib clean}

显然,Gradle 无法从 Appilcation.mk 中正确读取 APP_ABI。我已经尝试在所有可能的位置设置 abifilters,如下所示。
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
// For ndk-build, instead use the ndkBuild block.
ndkBuild {
// Sets optional flags for the C++ compiler.
abiFilters "armeabi-v7a", "arm64-v8a"
}
}

ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}

}
buildTypes {
release {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

debug {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
}
externalNativeBuild {
ndkBuild {
path file('src/main/jni/Android.mk')
}
}
}

尽管我付出了所有努力,但在同一步骤中构建仍然失败,我可以看到该应用程序仍在尝试为 APP_ABI = x86 构建,尽管明确指示不要这样做。

任何帮助,将不胜感激 ! TIA。

最佳答案

以防万一有人偶然发现同样的问题,在尝试了一切(包括 Build > Clean Project)之后,通过删除根项目目录中的 .gradle 文件夹并再次构建来解决上述问题。

关于即使在正确设置 abiFilters 之后,Android Studio 也会忽略 ndk-build 的 APP_ABI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58288521/

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