android - jni 库未包含在调试版本中
问题描述
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'
}
但是,如果我执行 Build -> Rebuild Project,生成的 apk 具有所需的 .so 文件。但是当我连接到设备并运行应用程序时,apk 不包括所需的 .so 文件。
我检查了 build/intermediates/merged_jni_libs 文件夹,它包含所有情况下所需的文件。
我正在使用 Android Studio 3.5 并使用 Android Gradle Plugin 3.5.0 和 Gradle 版本 5.4.1
解决方案
将架构变体显式添加到应用程序等级文件也有助于:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
abiFilters "armeabi"
}
}
debug {
ndk {
abiFilters "armeabi"
}
}
}
推荐阅读
- html - 如何有一个包含两列、三列或更多列的下拉菜单?
- android - 无法在 android 上运行 react-native 新项目
- c# - 激活触摸屏键盘的派生文本框
- python - 什么是命令行争论以及它们的用途是什么?
- r - 格式化字符列中的小数位。as.numeric 擦除列中的值
- excel - Excel中的文本到列数据拆分
- c - 我的 Clang 编译器采用哪种 C 标准(ANSI、c99...)?
- c# - 在 C# 中重构 if 语句块
- mysql - mySQL80 错误 1045 (28000)::Access Denied for user@localhost (使用密码: YES)
- c# - 如何使用 LINQ 在列表中找到最大值?