gpt4 book ai didi

java - 如何在 Android Studio 中正确创建从 AAR 导入的 Android 库模块?

转载 作者:行者123 更新时间:2023-12-03 05:44:35 25 4
gpt4 key购买 nike

AAR 的 Android 模块库是否损坏?

自从我升级我们的构建以使用 Android Gradle 插件的 3.1.2 后,我遇到了这个问题,即构建无法在 AAR 中找到构建版本,包括 jniLibs/和 libs/文件夹中的 jar。这曾经在 Android Gradle 3.1.2 插件之前工作。我只是将 aar 称为“library.aar”:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':toolbarsample:transformClassesWithInstantRunForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: Failed to find byte code for "class in jar file in the libs folder of the AAR"

失败的任务是 transformClassesWithInstantRunForDebug。当我禁用即时运行时,我遇到了一个问题,即我的应用程序无法在运行时运行,因为它找不到我的 jniLibs/文件夹,在该文件夹中,插件无法找到 bundle 为其中一部分的某些 java 类的字节码libs/文件夹中的 jars。

但是,如果我通过将以下行添加到我的应用程序的 build.gradle 将 aar 添加到应用程序的 libs 文件夹中,我的应用程序将编译并运行良好! implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
我什至尝试将库作为 gradle 库模块导入,它会自动生成这个 build.gradle:

configurations.maybeCreate("default")
artifacts.add("default", file('library.aar'))

我的 aar 是使用这些 build.gradle args 构建的:

apply plugin: 'com.android.library'

android {
compileSdkVersion versions.android.sdk
buildToolsVersion versions.android.buildTools

defaultConfig {
minSdkVersion versions.android.minSdk
targetSdkVersion versions.android.sdk
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
implementation libraries.android

testImplementation "junit:junit:$versions.junit"
}

有同样问题的人吗?我不知道这里发生了什么...

最佳答案

所以我已经回答了我自己的问题,但可能不是大多数人所期望的那样。

完整的细节在这里:https://www.reddit.com/r/androiddev/comments/9rlimj/android_library_dependency_management/e8i0qq2/?context=3

tl;博士我们正在通过文件使用我们的 AAR,而不是作为 gradle 库项目

关于java - 如何在 Android Studio 中正确创建从 AAR 导入的 Android 库模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50747310/

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