UnsatisfiedLinkError: couldn't find "libadblockplus-jni.so" in Android debug build

UnsatisfiedLinkError: couldn't find "libadblockplus-jni.so" in Android debug build

我正在使用 AdblockWebView

https://github.com/adblockplus/libadblockplus-android

在我的 Android 应用中。我有三种构建类型:"release"、"debug" 和 "dev",并且在我测试 "dev" 构建类型时 Webview 正在工作。

但是,当我启动 "debug" 类型时,它与 "dev" 不同,只有配置常量,当我打开 webview activity 时,应用程序毫无理由地崩溃。

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/app....debug-W8BipJfr6wKqz06J0zWgrQ==/base.apk"],nativeLibraryDirectories=[/data/app/app...debug-W8BipJfr6wKqz06J0zWgrQ==/lib/arm64, /data/app/app....debug-W8BipJfr6wKqz06J0zWgrQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libadblockplus-jni.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
    at java.lang.System.loadLibrary(System.java:1657)
    at org.adblockplus.libadblockplus.Platform.<clinit>(Platform.java:27)
    at org.adblockplus.libadblockplus.android.AdblockEngine$Builder.createEngines(AdblockEngine.java:265)
    at org.adblockplus.libadblockplus.android.AdblockEngine$Builder.build(AdblockEngine.java:250)
    at org.adblockplus.libadblockplus.android.SingleInstanceEngineProvider.createAdblock(SingleInstanceEngineProvider.java:174)
    at org.adblockplus.libadblockplus.android.SingleInstanceEngineProvider.access0(SingleInstanceEngineProvider.java:35)
    at org.adblockplus.libadblockplus.android.SingleInstanceEngineProvider.run(SingleInstanceEngineProvider.java:211)
    at java.lang.Thread.run(Thread.java:764)

我尝试删除 "dev" 构建类型,但这没有帮助。我试着在网上搜索了几个小时,但我发现唯一相关的是 this

build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'com.google.gms.google-services'

android {
    signingConfigs {
        config {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storeFile file('C:/Users/Name/.android/debug.keystore')
            storePassword 'android'
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "app.example"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 15
        versionName "1.3.9"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.config
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            debuggable true
            resValue "string", "app_name", "example debug"
            buildConfigField "String", "BACKEND_URL", '"https://api.example.com/"'
        }
        dev {
            applicationIdSuffix ".dev"
            debuggable true
            resValue "string", "app_name", "example dev"
            buildConfigField "String", "BACKEND_URL", '"https://dev.example.com/"'
            signingConfig signingConfigs.config
        }
        release {
            resValue "string", "app_name", "example"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BACKEND_URL", '"https://api.example.com/"'
        }
    }
    kapt {
        generateStubs = true
    }
    buildToolsVersion '28.0.3'
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
    implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
    implementation 'org.adblockplus:adblock-android-webview:3.0'
    implementation 'com.github.bumptech.glide:recyclerview-integration:4.8.0'
    implementation 'com.google.android:flexbox:0.3.2'
    implementation 'com.google.dagger:dagger:2.16'
    implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    kapt 'com.google.dagger:dagger-android-processor:2.16'
    implementation 'com.andkulikov:transitionseverywhere:1.8.0'
    kapt 'com.google.dagger:dagger-compiler:2.16'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.github.rubensousa:gravitysnaphelper:1.5'
    implementation 'com.github.takusemba:multisnaprecyclerview:1.3.4'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'org.slf4j:slf4j-nop:1.7.25'
    implementation 'com.github.stfalcon:stfalcon-imageviewer:0.1.0'
    implementation 'com.vk:androidsdk:1.6.9'
    implementation 'com.appyvet:materialrangebar:1.4.4'
    implementation 'com.github.ome450901:SimpleRatingBar:1.4.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-runtime:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.room:room-runtime:2.1.0-alpha04'
    kapt 'androidx.room:room-compiler:2.1.0-alpha04'
    implementation 'androidx.paging:paging-runtime:2.1.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    implementation 'io.sentry:sentry-android:1.7.16'
    implementation 'com.google.android.gms:play-services-gcm:16.1.0'
    implementation 'com.mixpanel.android:mixpanel-android:5.4.4'
    implementation 'com.amplitude:android-sdk:2.16.0'
    implementation 'io.branch.sdk.android:library:3.0.4'
    implementation 'com.android.support:customtabs:28.3.0'
    // Chrome Tab matching
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    implementation 'com.google.firebase:firebase-appindexing:17.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    // App indexing
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
}

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

它没有在应用程序的 libs 文件夹中生成 libadblockplus-jni.so

对我来说,它是在更新到 Android Gradle 3.5.0 后开始发生的。改回3.4.2后就可以了

尝试在项目结构中将 Android Gradle 插件版本更改为 3.4.2, 文件 > 项目结构 > 项目

Project Structure Menu

我遇到了同样的问题

implementation 'org.adblockplus:adblock-android-webview:3.0'

但是将 Gradle 插件版本降级到 3.4.2 是可行的,但我需要使用 Gradle 插件版本到 4.1 进行数据绑定。更新到

implementation 'org.adblockplus:adblock-android-webview:4.0'

它正在运行。我在项目结构中使用了 gradle plugin version 4.1.1gradle version 6.5。我能够屏蔽大部分广告,但仍有 5% 的广告绕过它。

  • 另请注意:此 adblockplus 库会使您的 apk 变大。在我的例子中,将 apk 大小从 11MB 更改为 33MB。在 Playstore
  • 上发布时使用捆绑包