gpt4 book ai didi

android - 将使用 AndroidX 的自定义 .aar 库添加到 Cordova 插件

转载 作者:行者123 更新时间:2023-12-03 05:07:20 26 4
gpt4 key购买 nike

客观的

我需要为 Cordova 开发一个插件,该插件实现了我已经为 Android 应用程序开发的一些代码(aar 文件)。

系统

  • 操作系统:Ubuntu 18.04.2 LTS
  • IDE:VSCode 和 Android Studio
  • 电话:Nexus 4 - Android 5.1.1
  • Cordova 版本:8.1.2 (cordova-lib@8.1.1)
  • Cordova 应用的 SDK 信息(来自 build.gradle):
  • defaultBuildToolsVersion="27.0.1" //String
    defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
    defaultTargetSdkVersion=27 //Integer - We ALWAYS target the latest by default
    defaultCompileSdkVersion=27 //Integer - We ALWAYS compile with the latest by default

    我试过的
  • 我已经从该项目中创建了一个 .aar 文件,并且正在尝试将其添加到我的 Cordova 插件中。我可以从该项目中导入方法,但是一旦我打开使用这些方法的 Activity (应用程序仍然正确构建),应用程序就会崩溃。
  • 03-21 12:35:59.728 12235-12235/io.cordova.hellocordova E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.cordova.hellocordova, PID: 12235
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/content/ContextCompat;
  • 我想这可能是因为 androidx感谢 Failed resolution of: Landroidx/core/content/ContextCompat; .所以我将该行添加到我的plugin.xml文件:

  • <!-- I have the same version of androidx.appcompat in my aar library -->
    <framework src="androidx.appcompat:appcompat:1.0.0-beta01"/>
  • 通过该更改,应用程序拒绝构建并且我得到了这些错误(我用 <projectpath> 替换了绝对项目路径):
  • AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/home/benjamin/.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0-beta01.aar/ad380179fb375e61241b11fa4df558eb/res/values-v28/values-v28.xml","position":{"startLine":8,"startColumn":4,"startOffset":447,"endLine":11,"endColumn":12,"endOffset":684}}],"original":"","tool":"AAPT"}
    AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/home/benjamin/Documents/Projects/Git/CordovaPluginProcessSdk/MobileApp/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml","position":{"startLine":10}}],"original":"","tool":"AAPT"}
    AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"/home/benjamin/.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0-beta01.aar/ad380179fb375e61241b11fa4df558eb/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
    AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"/home/benjamin/.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0-beta01.aar/ad380179fb375e61241b11fa4df558eb/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
    <projectpath>/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
    <projectpath>/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
    <projectpath>/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:228: error: resource android:attr/fontVariationSettings not found.
    <projectpath>/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:228: error: resource android:attr/ttcIndex not found.
    error: failed linking references.

    Failed to execute aapt
    com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:796)
    at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:551)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:285)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
    at sun.reflect.GeneratedMethodAccessor274.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    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:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    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:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    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:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    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.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
  • 有了这些错误,我开始认为这可能是 cordova 之间的错误。和 androidx图书馆。要检查我是否尝试使用该行添加不同的库( Volley ,我的 aar 库不需要它):
  • <framework src="com.android.volley:volley:1.1.1"/>
  • 应用程序构建成功。但是当我运行它时,一旦我们开始使用 AAR 库中的元素,它就会崩溃。 (参见步骤 1)

  • Cordova 与 androidx 兼容吗?如果是,是什么阻止我使用它?

    看起来它与我得到的测试和错误不兼容,但我没有在 Cordova 文档网站或谷歌搜索中找到有关该主题的相关信息。所以我无法确认。

    PS:我试图尽可能详尽,请询问您是否缺少信息。

    编辑#1:
  • 我试图改变androidx返回 appcompat在我的 .aar 库中。我生成了一个新的 .aar 并使用了

  • <framework src="com.android.support:appcompat-v7:28.0.0"/>

    而不是 androidx 导入。

    结果:与 (1.) 问题相同。

    结论:可能不是因为androidx
  • 我记得在 Cordova 的官方文档中,他们使用了 appcompat 的导入:Cordova - Plugin.xml - Framework .所以我用了这个:

  • <!-- Depend on v21 of appcompat-v7 support library -->
    <framework src="com.android.support:appcompat-v7:21+" />


    它构建正确。但仍然会崩溃,因为 .aar 文件中使用的函数对于此版本的库不存在。
    Process: io.cordova.hellocordova, PID: 16523
    java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/io.cordova.hellocordova-2/base.apk)

    如果可能的话,我想继续使用 androidx 而不是 appcompat,因为我还有其他依赖它的模块。

    最佳答案

    缺少的资源(ttcIndex 等)仅在 API 28 中添加 - 这就是它们位于名为 values-v28 的文件夹中的原因。 .

    您需要更新您的 compileSdkVersion到 28 才能成功编译。

    关于android - 将使用 AndroidX 的自定义 .aar 库添加到 Cordova 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55281348/

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