jni库未包含在调试版本中

时间:2019-10-02 15:07:06

标签: android android-studio android-gradle-plugin

Android调试版本缺少jniLibs文件夹中的.so文件。

下面给出了项目级别的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用级build.gradle如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.test.mobiocean"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs 'src/main/jniLibs'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Project file structure

但是,如果我执行Build-> Rebuild Project,则生成的apk具有所需的.so文件。但是,当我连接到设备并运行应用程序时,apk不包括所需的.so文件。

我已经检查了build / intermediates / merged_jni_libs文件夹,其中包含所有情况下所需的文件。

我正在使用Android Studio 3.5和Android Gradle插件3.5.0和Gradle版本5.4.1

2 个答案:

答案 0 :(得分:0)

一种解决方法:

  1. 在AS中运行“构建”
  2. 在您的设备上安装apk并运行
  3. 将调试器附加到进程

我认为这是AS的错误。我遇到了同样的问题:“构建”或运行“ gradlew:app:assembleDebug”有效,而运行调试无效。如果Gradle of Gradle插件中存在错误,则“ Build”或“ gradlew:app:assembleDebug”也将失败。

答案 1 :(得分:0)

明确地将architecure变体添加到应用程序等级文件中也有帮助:

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