I'm trying to set up splits which should include different asset files for different abis.
However, when trying to run it on my x86 emulator, I get the following errors during build:
Cannot build selected target ABI: x86, no suitable splits configured: arm64-v8a;
Cannot build selected target ABI: x86, no suitable splits configured: armeabi-v7a;
Cannot build selected target ABI: x86, no suitable splits configured: x86_64;
My build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.mnemosyne"
minSdkVersion 21
targetSdkVersion 28
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_static'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
flavorDimensions "abi"
productFlavors {
armeabi_v7a {
dimension "abi"
ndk.abiFilters 'armeabi-v7a'
}
arm64_v8a {
dimension "abi"
ndk.abiFilters 'arm64-v8a'
}
x86 {
dimension "abi"
ndk.abiFilters 'x86'
}
x86_64 {
dimension "abi"
ndk.abiFilters 'x86_64'
}
}
sourceSets {
armeabi_v7a {
jniLibs.srcDirs = ['../dependencies/python/lib/armeabi-v7a']
assets.srcDirs = ['../dependencies/python/lib/armeabi-v7a/',
'../dependencies/python/lib/armeabi-v7a/modules/']
}
arm64_v8a {
jniLibs.srcDirs = ['../dependencies/python/lib/arm64-v8a']
assets.srcDirs = ['../dependencies/python/lib/arm64-v8a/',
'../dependencies/python/lib/arm64-v8a/modules/']
}
x86 {
jniLibs.srcDirs = ['../dependencies/python/lib/x86']
assets.srcDirs = ['../dependencies/python/lib/x86/',
'../dependencies/python/lib/x86/modules/']
}
x86_64 {
jniLibs.srcDirs = ['../dependencies/python/lib/x86_64']
assets.srcDirs = ['../dependencies/python/lib/x86_64',
'../dependencies/python/lib/x86_64/modules/']
}
}
externalNativeBuild {
cmake {
version '3.10.2'
path 'src/main/cpp/CMakeLists.txt'
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
}
}
Related
I am working on Android project whose build.gradle looks like this:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
tasks.whenTaskAdded { task ->
if (task.name.contains("externalNativeBuild") || task.name.contains("buildCMake")) {
if(project.hasProperty("native")) {
//task.dependsOn(tasks.getByName("abc-all"))
tasks.getByName("abc-all").finalizedBy(task.name)
// xyz.finalizedBy(task.name)
} else {
//task.enabled = false
}
}
}
ant.importBuild 'build.xml'
android {
compileSdk 32
flavorDimensions "default","abi"
productFlavors {
devBuild {
dimension "default"
// This flavor is used to speed up the time required for building APKs
// In this intune is disabled. Only en and "xxhdpi" resources are bundled. and dynamically changing buildconfig value is made a constant.
resValue "bool", "isDevBuildVariant", "true"
resConfigs "en", "xxhdpi"
}
appCenter {
dimension "default"
}
fat {
dimension "abi"
ndk {
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
armv7 {
dimension "abi"
ndk {
abiFilters "armeabi-v7a"
}
}
arm64 {
dimension "abi"
ndk {
abiFilters "arm64-v8a"
}
}
x86 {
dimension "abi"
ndk {
abiFilters "x86"
}
}
x86_64 {
dimension "abi"
ndk {
abiFilters "x86_64"
}
}
}
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "--warn-uninitialized",
"-DANDROID_TOOLCHAIN=clang",
"-DANDROID_PLATFORM=android-21",
"-DSHARED_LIBRARY=1",
"-DOFFLINE_SYNC_SUPPORT_ENABLED=0"
}
}
}
buildTypes {
stage {
}
debug {
}
release {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
However the problem is I am unable to switch build varient in Android Studio.
I am able to switch from appCenterArm64Debug to appCenterFatDebug but not from appCenterArm64Debug to appCenterArmv7 or appCenterX86.
Looks like I am only able to change Active ABI from arm64-v8a to fat but not to any other ABI.
When I comment externalNativeBuild block inside android{}, the problem goes away but then I can't choose Active ABI.
Do I have add anything to gradle.
Everything compiled well and my apk is built, but at runtime I get this error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "../../../../libs/x86/mylib.so" not found
I tried to extract the apk and check libs/x86 folder and the .so is there.
My android field at app/build.gradle is:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.example.test"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters "x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
Recently i have tried to attach cmake with my existing android studio project. I am searching SO since last four day not yet succeeded. Please don't mark this as duplicate. I am running android studio 2.2.1 with gradle version 2.14.1 in windows 8.1pro.
My build.gradle (app level):
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId = "com.example.user.myproject"
minSdkVersion 17
targetSdkVersion 24
multiDexEnabled true
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// proguardFiles.add(file("proguard-rules.txt"))
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
productFlavors {
arm7 {
// in the future, ndk.abiFilter might also work
ndk {
abiFilter 'armeabi-v7a'
}
}
arm8 {
ndk {
abiFilters 'arm64-v8a'
}
}
arm {
ndk {
abiFilter 'armeabi'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
mips {
ndk {
abiFilters 'mips', 'mips64'
}
}
universal {
ndk {
abiFilters 'mips', 'mips64', 'x86', 'x86_64'
}
}
}
}
dependencies {
My CMakeLists.txt (path: 'app/src/main/cpp')
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib
SHARED
src/main/cpp/native-lib.cpp)
I am getting this error in message view:
Error while executing 'C:\Users\User\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe' with arguments {-HF:\MyProject\app\src\main\cpp -BF:\MyProject\app\.externalNativeBuild\cmake\x86_64Debug\x86_64 -GAndroid Gradle - Ninja -DANDROID_ABI=x86_64 -DANDROID_NDK=C:\Users\User\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=F:\MyProject\app\build\intermediates\cmake\x86_64\debug\obj\x86_64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Users\User\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\User\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_TOOLCHAIN=clang}
I don't know what's wrong here.
I am trying to launch my android application in debug mode, but everytime I check BuildConfig.DEBUG it says it is false. Even further, a buildconfigField defined in my buildtypes does not even show up in BuildConfig.
Here is my gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.22.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
def versionMajor = 1
def versionMinor = 2
def versionPatch = 41
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
android {
compileOptions.encoding = 'ISO-8859-1'
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.name"
minSdkVersion 17
targetSdkVersion 21
buildConfigField 'Boolean', 'enableCrashlytics', 'false'
multiDexEnabled true
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
}
signingConfigs {
release {
// release stuff
}
}
buildTypes {
android {
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
debug {
buildConfigField 'Boolean', 'enableCrashlytics', 'false'
debuggable true
minifyEnabled false
applicationIdSuffix ".debug"
}
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/res/xml']
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
// ... some other libs
compile('com.crashlytics.sdk.android:crashlytics:2.6.6#aar') {
transitive = true;
}
}
So in Android Studio I chooseBuild Variant "debug" for my app, but when I hit a breakpoint in the application and check the values of BuildConfig, the filed enableCrashlytics cant be resolved and the value of BuildConfig.BUILD_TYPE is "release".
What am I doing wrong?
This may happen if the code is in a library, there are multiple BuildConfig classes in a project, one per module, and only the main app one will be updated as expected.
If you want to have a proper BuildConfig.BUILD_TYPE across the app, you'd need to have debug/release build types on all your modules' gradle files, and trickle down the selected build-type from the main gradle file to the dependencies.
my build.grandle code is this one:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.assus.appweather"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName = "odroid_weather"
abiFilter "x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs 'main/src/libs'
}
}
productFlavors{
x86 {
ndk {
abiFilter "x86"
}
armv7a{
ndk {
abiFilter "armeabi-v7a"
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
}
and when I build my project, always this error is shown :
gradle dsl method not found: ' armv7a'
Gradle sync failed: Gradle DSL method not found: 'armv7a()'
Consult IDE log for more details (Help | Show Log)
some one can help me please !
Perhaps you meant to have a productFlavors that looks like this instead (it looks like you missing a closing brace):
productFlavors{
x86 {
ndk {
abiFilter "x86"
}
}
armv7a {
ndk {
abiFilter "armeabi-v7a"
}
}
}