capacitor的android项目接入穿山甲遇到的坑

1. 根据文档使用自动拉取adapter工具配置build.gradle,点击“Sync Project With Gradle Files”报错:

Caused by: org.gradle.api.GradleException: 未查找到与baidu 版本为:9.3941 匹配的adapter,请更新SDK至合适版本,如有疑问请联系技术支持。

解决方式是放弃自动拉取adapter工具配置,需要在maven中引入adapter包:

    //---------- GDT ----------
    implementation 'com.pangle.cn:mediation-gdt-adapter:4.642.1512.0'
    implementation(name: "GDTSDK.unionNormal.4.642.1512", ext: 'aar')  //GDT 优量汇 sdk ,通过aar方式引入, 需要把相关aar放到libs目录下,需要保证aar名称和版本号的准确

 

2. 点运行时报错:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bytedance.sdk.openadsdk.TTFileProvider" on path: DexPathList[[zip file "/data/app/~~Ol1vZKiGBPJT4eFuTS5Zyw==/org.capacitor.hjdang-LCtWyqH4mRo9kBlC5ZdjAw==/base.apk"],nativeLibraryDirectories=[/data/app/~~Ol1vZKiGBPJT4eFuTS5Zyw==/org.capacitor.hjdang-LCtWyqH4mRo9kBlC5ZdjAw==/lib/x86_64, /system/lib64, /system_ext/lib64]]

根据官方文档,配置中有:

AndroidManifest.xml

        <provider
          android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
          android:authorities="${applicationId}.TTFileProvider"
          android:exported="false"
          android:grantUriPermissions="true">
          <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/pangle_file_paths" />
        </provider>

解压过打的apk包,发现包里没有这个类。后来搜了下,原来是我这个项目是AndroidX项目(android.useAndroidX=true),在而依赖的包却还是老的依赖。由于这个问题还导致了其他的一些问题,如Manifest合并过程中会报重复class的问题。

解决方法:

在project的gradle.properties里加上 android.enableJetifier=true

android.useAndroidX=true
android.enableJetifier=true

会把依赖自动转换成AndroidX的。

# Post author: 文理兼修电脑首席 @若批评不自由,则赞美无意义
# Post link: https://limxtop1989.github.io/limxtop/2023/08/06/AndroidX-migrate/

Migrate an existing project using Android Studio With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar. The refactor command makes use of two flags. By default, both of them are set to true in your gradle.properties file: android.useAndroidX=true The Android plugin uses the appropriate AndroidX library instead of a Support Library. android.enableJetifier=true The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.

 

3. 和原来配置有冲突。在AndroidManifest <application>加上

tools:replace="android:allowBackup"
Attribute application@allowBackup value=(true) from AndroidManifest.xml:5:9-35
    is also present at [:GDTSDK.unionNormal.4.642.1512:] AndroidManifest.xml:28:9-36 value=(false).
    Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml

 

 

 
 
Plugin Icon
 
 
 
Plugin Icon
 
 
Plugin Icon
 
 
Plugin Icon
posted @ 2025-09-23 01:03  zjhgx  阅读(25)  评论(0)    收藏  举报