Could not find method path() for arguments - android

Please someone help me, I'm stuck here.
apply plugin: 'com.android.application'
android{
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.glitchrun.sapphire"
minSdkVersion 14
targetSdkVersion 26
externalNativeBuild {
ndkBuild {
path "$projectDir/jni/Android.mk"
}
}
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86"
cppFlags "-frtti -fexceptions"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
This is my error and I don't know what to do.
Could not find method path() for arguments [C:\Users\costy\AndroidStudioProjects\android\app/jni/Android.mk] on object of type com.android.build.gradle.internal.dsl.ExternalNativeNdkBuildOptions.
I'm trying to export a .apk file and I was stuck with the Deprecated NDK problem. Now I'm stuck with this problem.

The externalNativeBuild block that specifies the makefile path should not be part of defaultConfig, but of its android parent:
android {
compileSdkVersion 26
// etc...
defaultConfig {
applicationId "com.glitchrun.sapphire"
// etc...
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86"
cppFlags "-frtti -fexceptions"
}
}
}
// etc...
externalNativeBuild {
ndkBuild {
path "$projectDir/jni/Android.mk"
}
}
}
The inner one is used to modify ExternalNativeBuildNdkOptions, while the outer one is used to modify NdkBuildOptions.

Related

Android gradle : can't switch build varient with Active ABI

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.

dlopen cannot find .so library at runtime

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"
}
}
}

External native build issues, build command failed, error while executing 'C:/User/user.../cmake.exe' with arguments {-HF

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.

How to add cpufeatures to android jni cmake gradle build?

If I have a build.gradle for an application:
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.ndkcmaketest.headwayent.ndkcmaketest"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=gcc"//, "-DANDROID_ALLOW_UNDEFINED_SYMBOLS=TRUE"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
How do I add cpufeatures as ldlibs? Adding ldLibs.addAll(["cpufeatures"]) in externalNativeBuild does not work. And neither adding in an ndk block.
Do you have to add this to build.gradle specifically? If not, add the following to one of your CMakeLists.txt files:
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()
Then you can target_link_libraries(<your target>, cpufeatures).
That macro and a couple of others are defined in $ANDROID_SDK/cmake/<cmake-version>/share/cmake-<version>/Modules/AndroidNdkModules.cmake.

gradle dsl method not found: ' armv7a'

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"
}
}
}

Categories

Resources