I'm migrating a project from gradle-experimental:0.8.3 to gradle:2.3.3 .
Along with it I need to also start using the new cmake which is proving to not be so straight forward.
A snippet for the experimental gradle plugin that worked:
repositories {
libs(PrebuiltLibraries) {
// Configure one pre-built lib: shared
crypto {
// Inform Android Studio where header file dir for this lib
headers.srcDir "${lib_distribution_root}/openssl/includes"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("${lib_distribution_root}/openssl/lib/armeabi/libcrypto.so")
}
}
openssl {
// Inform Android Studio where header file dir for this lib
headers.srcDir "${lib_distribution_root}/openssl/includes"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("${lib_distribution_root}/openssl/lib/armeabi/libssl.so")
}
}
pjsip {
// Inform Android Studio where header file dir for this lib
headers.srcDir "${lib_distribution_root}/pjsip/includes"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("${lib_distribution_root}/pjsip/lib/armeabi/libpjsua.so")
}
}
}
}
android {
def globalConfiguration = rootProject.ext
compileSdkVersion = globalConfiguration.androidCompileSdkVersion
buildToolsVersion = globalConfiguration.androidBuildToolsVersion
defaultConfig.with {
minSdkVersion.apiLevel = globalConfiguration.androidMinSdkVersion
targetSdkVersion.apiLevel = globalConfiguration.androidTargetSdkVersion
multiDexEnabled = true
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions.with {
javaMaxHeapSize = "4g"
}
lintOptions.with {
abortOnError = false
}
sources {
main {
jni {
dependencies {
library 'crypto' linkage 'shared'
library 'openssl' linkage 'shared'
library 'pjsip' linkage 'shared'
}
}
jniLibs {
// for shared lib, lib need to be pushed to the target too
// Once libs are copied into app/src/main/jniLibs directory,
// Android Studio will pack them into APK's lib/ directory
// Here we like to avoid another duplication by pointing
// to the files that containing our libs' distribution location
// so the same file is used by compiler at host, also packed
// into APk to be used at Target (phone/tablet)
source {
srcDir "${lib_distribution_root}/openssl/lib/armeabi"
srcDir "${lib_distribution_root}/pjsip/lib/armeabi"
}
}
}
}
ndk {
moduleName = "datanative"
platformVersion = 19
stl = "gnustl_static"
ldLibs.addAll("android", "stdc++", "log", "GLESv2", "EGL", "OpenSLES", "z", "m")
cppFlags.addAll("-std=c++11", "-frtti", "-fexceptions", "-pthread", "-fpic", "-ffunction-sections", "-funwind-tables")
cppFlags.add("-DPJ_AUTOCONF")
abiFilters.add(abiName)
cppFlags.add("-marm")
}
}
}
The current work-in-progress has the gradle config:
android {
def globalConfiguration = rootProject.ext
compileSdkVersion globalConfiguration.androidCompileSdkVersion
buildToolsVersion globalConfiguration.androidBuildToolsVersion
defaultConfig {
minSdkVersion globalConfiguration.androidMinSdkVersion
targetSdkVersion globalConfiguration.androidTargetSdkVersion
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-DPJ_AUTOCONF", "-fpic", "-frtti", "-fexceptions", "-pthread", "-ffunction-sections", "-funwind-tables", "-marm"
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=gnustl_static'
}
}
ndk {
moduleName "datanative"
abiFilters 'armeabi'
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
sourceSets {
main {
jniLibs.srcDirs '../distribution/pjsip/lib/armeabi/', '../distribution/openssl/lib/armeabi/', 'src/main/cpp/'
}
}
dexOptions.with {
javaMaxHeapSize = "4g"
}
lintOptions.with {
abortOnError = false
}
}
And the CMakeLists:
cmake_minimum_required(VERSION 3.4.1)
file(GLOB SOURCES
src/main/cpp/*.h
src/main/cpp/*.cpp
)
set(distribution_DIR ${path})
include_directories(src/main/cpp/)
include_directories(../distribution/openssl/includes/)
include_directories(../distribution/pjsip/includes/)
add_library( crypto SHARED IMPORTED )
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
absolute_path_cause_gradle_has_error_otherwise/distribution/openssl/lib/armeabi/libcrypto.so )
add_library( ssl SHARED IMPORTED )
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
absolute_path_cause_gradle_has_error_otherwise/distribution/openssl/lib/armeabi/libssl.so )
add_library( pjsip SHARED IMPORTED )
set_target_properties(pjsip PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
absolute_path_cause_gradle_has_error_otherwise/distribution/pjsip/lib/armeabi/libpjsua.so )
add_library( data SHARED ${SOURCES} )
target_link_libraries(data crypto ssl pjsip)
The linking error that I'm facing and maybe not the root cause:
/src/main/cpp/sthread.cpp
Error:(73) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE'
Error:(73) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE'
/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h
Error:(547) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE'
Error:(547) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE'
Any clue will be apreciated.
Thank you!
Related
Reading through the README on the SuperPowered SDK GitHub page, I notice that for having it working on Android you need to:
Create the jni folder inside the project's folder: app/src/main/jni
Copy the contents of the following files from one of the example
projects: gradle/wrapper/gradle-wrapper.properties, local.properties,
build.gradle, app/build.gradle, app/src/main/jni/CMakeLists.txt Open
build.gradle (Module: app), and change the applicationId
I've done all of that, still when I'm trying to sync my project with gradle, I get the following error message:
Error:(34, 0) Could not find method arguments() for arguments [-DANDROID_PLATFORM=android-16, -DANDROID_TOOLCHAIN=clang, -DANDROID_ARM_NEON=TRUE, -DANDROID_STL=gnustl_static, -DPATH_TO_SUPERPOWERED:STRING=null] on object of type com.android.build.gradle.internal.dsl.CmakeOptions.
Open File
This is how my app/build.gradle looks like:
apply plugin: 'com.android.application'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def superpowered_sdk_path = properties.getProperty('superpowered.dir')
android {
signingConfigs {
dancam_dev_key {
keyAlias ######
keyPassword ######
storeFile file('/Users/daniele/Desktop/Chords/#####')
storePassword ########
}
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId #####
minSdkVersion 21
targetSdkVersion 26
versionCode 17
versionName "2.1"
signingConfig #######
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' // these platforms cover 99% percent of all Android devices
}
}
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-16', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_ARM_NEON=TRUE', '-DANDROID_STL=gnustl_static', "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}"
cFlags '-O3', '-fsigned-char' // full optimization, char data type is signed
cppFlags '-fsigned-char', "-I${superpowered_sdk_path}"
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
dataBinding {
enabled = true
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jni']
}
}
externalNativeBuild {
cmake {
path 'src/main/jni/CMakeLists.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
}
EDIT:
Here is the cmake.txt file
cmake_minimum_required(VERSION 3.4.1)
set(
PATH_TO_SUPERPOWERED
CACHE STRING ""
)
message(${ANDROID_ABI})
file(GLOB CPP_FILES "*.cpp")
add_library(
SuperpoweredExample
SHARED
${CPP_FILES}
${PATH_TO_SUPERPOWERED}/AndroidIO/SuperpoweredAndroidAudioIO.cpp
)
include_directories(src/main/jni)
include_directories(${PATH_TO_SUPERPOWERED})
target_link_libraries(
SuperpoweredExample
log
android
OpenSLES
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
)
I have a very similar config (as it inherits the default suggested config) but found some differences.
You provide the cmake config like this:
externalNativeBuild {
cmake {
path 'src/main/jni/CMakeLists.txt'
}
}
but as I understood you saved it as "cmake.txt" which is never linked or found.
Does renaming cmake.txt to CMakeLists.txt help?
I have 4 gradle build files: when I build in android studio I am constantly having the error:
No signature of method:
org.gradle.model.ModelMap.getDefaultProguardFile() is applicable for
argument types: (java.lang.String) values: [proguard-android.txt]
file 1
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.9.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
file 2
apply plugin: 'com.android.model.native'
model {
android {
compileSdkVersion = 25
buildToolsVersion = '25.0.0'
defaultConfig {
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 25
versionCode = 1
versionName = '1.0'
}
ndk {
moduleName = 'fpextractor'
platformVersion = 17
toolchain = "clang"
stl = 'gnustl_static' //std::mutex not in gnustl_static
cppFlags.add('-std=c++11')
abiFilters.addAll(['armeabi', 'armeabi-v7a', 'x86'])
//abiFilters.addAll(['armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64']) //this is default
//abiFilters.addAll(['armeabi'])
ldLibs.addAll(['android', 'log', 'atomic', 'z'])
}
}
}
// This is just copy out the header file and built lib into distribution
// directory for clint application to use; it is a small overhead of this sample:
// both lib and app are put inside one project space [save maintenance time]
task(distributeLib, type : Copy) {
// trigger build library
dependsOn assemble
into '../distribution/fpextractor/'
from('src/main/jni/fp_extractor.h') {
into 'include/'
}
from('build/outputs/native/release/lib') {
into 'lib/'
}
}
file 3
apply plugin: 'com.android.model.native'
model {
android {
compileSdkVersion = 25
buildToolsVersion = '25.0.0'
defaultConfig {
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 25
versionCode = 1
versionName = '1.0'
}
ndk {
moduleName = 'nativeaudio'
platformVersion = 17
toolchain = "clang"
stl = 'gnustl_static' //std::mutex not in gnustl_static
cppFlags.add('-std=c++11')
abiFilters.addAll(['armeabi', 'armeabi-v7a', 'x86'])
//abiFilters.addAll(['armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64']) //this is default
//abiFilters.addAll(['armeabi-v7a'])
ldLibs.addAll(['android', 'log', 'OpenSLES', 'atomic'])
}
}
}
// This is just copy out the header file and built lib into distribution
// directory for clint application to use; it is a small overhead of this sample:
// both lib and app are put inside one project space [save maintenance time]
task(distributeLib, type : Copy) {
// trigger build library
dependsOn assemble
into '../distribution/nativeaudio/'
from('src/main/jni/buf_manager.h') {
into 'include/'
}
from('src/main/jni/android_debug.h') {
into 'include/'
}
from('src/main/jni/debug_utils.h') {
into 'include/'
}
from('src/main/jni/audio_common.h') {
into 'include/'
}
from('src/main/jni/audio_recorder.h') {
into 'include/'
}
from('build/outputs/native/release/lib') {
into 'lib/'
}
}
file 4
apply plugin: 'com.android.model.application'
// Root of 3rd party lib(s): location could be anywhere on the host system
def lib_distribution_root = '../distribution'
model {
repositories {
libs(PrebuiltLibraries) {
// Configure one pre-built lib: shared
nativeaudio {
// Inform Android Studio where header file dir for this lib
headers.srcDir "${lib_distribution_root}/nativeaudio/include"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("${lib_distribution_root}/nativeaudio/lib/${targetPlatform.getName()}/libnativeaudio.so")
}
}
fpextractor {
// Inform Android Studio where header file dir for this lib
headers.srcDir "${lib_distribution_root}/fpextractor/include"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("${lib_distribution_root}/fpextractor/lib/${targetPlatform.getName()}/libfpextractor.so")
}
}
// Configure another pre-built lib: shared;[change to static after Studio supports]
// static lib generation. USING static lib is supported NOW, for that case,
// simple change:
// SharedLibaryBinary --> StaticLibraryBinary
// sharedLibraryFile --> staticLibraryFile
// *.so --> *.a
//gperf {
// headers.srcDir "${lib_distribution_root}/gperf/include"
// binaries.withType(SharedLibraryBinary) {
// sharedLibraryFile = file("${lib_distribution_root}/gperf/lib/${targetPlatform.getName()}/libgperf.so")
// }
//}
}
}
android {
compileSdkVersion = 25
buildToolsVersion = '25.0.0'
defaultConfig {
applicationId='com.gfk.mediawatchapp'
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 25
versionCode = 22
versionName = '255.0.4'
// Enabling multidex support.
//multiDexEnabled true
}
ndk {
platformVersion = 17
moduleName = 'mwlib'
toolchain = "clang"
stl = 'gnustl_static'
cppFlags.add('-std=c++11')
ldLibs.addAll(['android', 'log', 'OpenSLES', 'atomic'])
//build a default combined apk including all ABIs.
//abiFilters.addAll(['armeabi-v7a'])
abiFilters.addAll(['armeabi', 'armeabi-v7a', 'x86']) //this is default
}
sources {
main {
jni {
dependencies {
library 'nativeaudio' linkage 'shared'
library 'fpextractor' linkage 'shared'
// if gperf were *.a, change shared --> static
//library 'gperf' linkage 'shared'
}
}
jniLibs {
// for shared lib, lib need to be pushed to the target too
// Once libs are copied into app/src/main/jniLibs directory,
// Android Studio will pack them into APK's lib/ directory
// Here we like to avoid another duplication by pointing
// to the files that containing our libs' distribution location
// so the same file is used by compiler at host, also packed
// into APk to be used at Target (phone/tablet)
source {
srcDir "${lib_distribution_root}/nativeaudio/lib"
srcDir "${lib_distribution_root}/fpextractor/lib"
//srcDir "${lib_distribution_root}/gperf/lib"
}
}
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles.add(file('proguard-android.txt'))
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
}
dependencies {
println rootProject.getName()
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:25.3.1'
compile 'commons-net:commons-net:3.5'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.amazonaws:aws-android-sdk-core:2.4.2'
compile 'com.amazonaws:aws-android-sdk-s3:2.4.2'
compile 'com.amazonaws:aws-android-sdk-ddb:2.4.2'
compile 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.4.2'
}
// Unnecessary dependency management:
// Make sure the libs are available when begin compiling application project
// This could be ignored because in real scenario, the pre-built libs are
// already given to us before creating application.
tasks.whenTaskAdded { task ->
if (task.name.contains('compile')) {
task.dependsOn ':nativeaudio:distributeLib'
task.dependsOn ':fpextractor:distributeLib'
}
}
Please: Can anyone help me to understand why I have always the following error:
No signature of method:
org.gradle.model.ModelMap.getDefaultProguardFile() is applicable for
argument types: (java.lang.String) values: [proguard-android.txt]
Gradle experimental does not include getDefaultProguardFile() since it does not have any version of ProGuard config by default.
You can use move the lines from your proguard-android.txt to proguard-rules.pro and then change this line:
proguardFiles.add(file('proguard-android.txt'))
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
into this:
proguardFiles.add(file('proguard-rules.pro'))
For me adding a manifest with
jar {
manifest {
attributes 'Main-Class': com.package.to.main.Class
}
}
helped.
See here: Creating runnable JAR with Gradle
I am trying to build FFMPEG into my JNI code with gradle in Android Studio. I have build FFMPEG as a .so file, in order to adapt different platform, I build it for different ABI(arm64-v8a, armeabi-v7a, mip, etc).Then I need to determine the ABI of the current build in the build.gradle file.
Refer Experimental Plugin User Guide, my build.gradle look like this:
apply plugin: 'com.android.model.native'
model{
repositories {
prebuilt(PrebuiltLibraries){
ffmpeg{
headers.srcDir "src/main/jni/build/${targetPlatform.getName()}/include"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/jni/build/${targetPlatform.getName()}/libvflibrary.so")
}
}
}
}
android {
compileSdkVersion = 24
buildToolsVersion = "23.0.3"
defaultConfig {
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 24
versionCode = 1
versionName = "1.0"
}
ndk{
//platformVersion = 21
moduleName = "library-jni"
stl = 'gnustl_static'
toolchain = "clang"
abiFilters.addAll(['armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips'])
cppFlags.addAll(['-std=c++11', '-D__STDC_CONSTANT_MACROS'])
ldLibs.addAll(['log', 'android', 'z', 'EGL', 'GLESv2'])
}
sources {
main {
jni {
source{
srcDirs 'src/main/jni'
}
dependencies {
library 'ffmpeg' linkage 'shared'
}
}
}
}
}
}
I am getting an error:
Error:No such property: targetPlatform for class:
com.android.build.gradle.managed.NdkConfig.
Does anyone have an idea on how I can solve this, please?
I am Using Android Studio 1.5.1 Gradle version 2.8. Gradle experimental plugin v0.4.0
I have a library with native C code and java code as well. I am generating a library CoreLib-fat-release.aar with native libraries for all architectures(libcore.so) - arm64-v8a, armeabi, armeabi-v7a, mips, mips64, x86, x86-64.
I have a second library depending on my Core library. I made Core library as shared library.
In second library gradle file:
jni {
dependencies {
project ":CoreLib" buildType "release" productFlavor "fat" linkage "shared"
}
}
It is able to build properly, but when I open and see the second library aar file, I dont see libcore.so in all architecture folders.
Eg:
SecondLibrary-fat-release.aar => SecondLibrary-fat-release-zip
Inside SecondLibrary-fat-release/jni folder, only x86 and x86_64 folder contains libcore.so file. Other folders (arm64-v8a, armeabi, armeabi-v7a, mips, mips64) doesnot contain libcore.so file.
Because of this reason, if I use my Second Library in a 64 bit device, it is complaining UnSatisfiedLink error saying Found 32-bit library instead of 64-bit.
HEre is my build.gradle of second library:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 21
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
}
lintOptions.with {
abortOnError = false
}
}
android.ndk {
moduleName = "secondlibrary
cppFlags.addAll("-I${file(folder_path)}".toString(),
"-I${file(sourcesDir +folder1)}".toString(),
"-I${file(sourcesDir +folder2)}".toString(),
)
cppFlags.add("-frtti")
cppFlags.add("-fexceptions")
CFlags.addAll("-I${file(folder_path)}".toString(),
"-I${file(sourcesDir +folder1)}".toString(),
"-I${file(sourcesDir +folder2)}".toString(),
)
CFlags.add("-O3")
CFlags.add("-funroll-loops")
CFlags.add("-Wall")
ldLibs.addAll(["android", "log", "stdc++", "c", "m", "z", "EGL", "GLESv2"])
stl = "gnustl_shared"
}
// jni is the default dir; config this if yours is in different directory
android.sources {
androidTest {
java {
source {
srcDirs '../test_sources_path/src'
}
}
}
main {
manifest {
source {
srcDirs '.'
}
}
java {
source {
srcDir "src"
}
}
jni {
dependencies {
project ":CoreLib" buildType "release" productFlavor "fat" linkage "shared"
}
source {
srcDirs = ["jni",
path1,
path2,
"libcore.so"]
}
}
jniLibs {
dependencies {
library file(path_to_binaries + "libcore.so") abi "armeabi"
library file(path_to_binaries + "libcore.so") abi "x86"
library file(path_to_binaries + "libcore.so") abi "armeabi-v7a"
library file(path_to_binaries + "libcore.so") abi "mips"
library file(path_to_binaries + "libcore.so") abi "x86_64"
library file(path_to_binaries + "libcore.so") abi "arm64-v8a"
library file(path_to_binaries + "libcore.so") abi "mips64"
}
}
}
}
android.productFlavors {
create("fat")
}
repositories {
libs(PrebuiltLibraries) {
CoreLib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(path_to_binaries + "${targetPlatform.getName()}/libcore.so")
}
}
}
}
}
dependencies {
compile project(':CoreLib-fat-release')
}
NOTE: If I make CoreLib linkage as 'static' instead of 'shared', then all libcore.so files are copied properly to all the folders.
Please let me know if this is a programming issue or a bug in experimental plugin. Please suggest me if you know any alternative? Thank you.
This problem got resolved by the doing the following:
I have changed the experimental plugin version from 0.4.0 to 0.7.0 (gradle version 2.10).
Changes required in build.gradle:
We need to define variables outside model element.
we can remove
jniLibs {
dependencies {
library file(path_to_binaries + "libcore.so") abi "armeabi"
library file(path_to_binaries + "libcore.so") abi "x86"
library file(path_to_binaries + "libcore.so") abi "armeabi-v7a"
library file(path_to_binaries + "libcore.so") abi "mips"
library file(path_to_binaries + "libcore.so") abi "x86_64"
library file(path_to_binaries + "libcore.so") abi "arm64-v8a"
library file(path_to_binaries + "libcore.so") abi "mips64"
}
}
As this block of code is sufficient:
repositories {
libs(PrebuiltLibraries) {
CoreLib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(path_to_binaries + "${targetPlatform.getName()}/libcore.so")
}
}
}
I have a native library which I am trying to build with gradle. If I invoke the ndk-build command from the gradle file, I am able to build the native library. But if I try to use the ndk build functionality built in the android gradle plugin I an unable to build.
I get fatal error: android_native_app_glue.h: No such file or directory
The relevant section of the gradle file is:
buildTypes.debug.jniDebugBuild true
defaultConfig {
ndk {
moduleName 'myModule'
stl 'gnustl_static'
cFlags '-UNDEBUG -Werror -Wunused-variable -Wunused-but-set-parameter -Wtype-limits -Wmissing-field-initializers -Wreturn-type -Wuninitialized'
ldLibs 'log', 'GLESv2'
}
productFlavors {
armv7{
ndk {
abiFilter 'armeabi-v7a'
}
}
}
}
Is there a way to tell the ndk build where to find the android_native_app_glue.h file?
On a side note, is there a way to pass the verbose flag to ndk-build, the equivalent of ndk-build V=1 ?
I had the same issue and I fixed it by adding "-I{path_to_android-ndk}/sources/android/native_app_glue" to cFlags, see here
As of:
gradle-experimental:0.6.0-alpha2
gradle-2.9-all.zip
One way to do it (Or to integrate any code that can be compiled and link as a static library) is to create in your project a new module, and change the gradle file of that module to be:
apply plugin: 'com.android.model.library'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "0.0.1"
}
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
}
android.ndk {
moduleName = "native-activity"
cppFlags.add("-Werror")
ldLibs.addAll(["log", "android"])
stl = "gnustl_static"
ldFlags.add("-c")
}
android.sources {
main {
jni {
source {
srcDir "${ndkDir}/sources/android/native_app_glue"
}
}
}
}
}
Then in your module's gradle.mk you should just add:
apply plugin: 'com.android.model.application'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
model {
android {
[...]
}
android.ndk {
[...]
cppFlags.add("-I${file("${ndkDir}/sources/android/native_app_glue")}".toString())
}
android.sources {
main {
jni {
dependencies {
project ":native-activity" linkage "static"
}
}
}
}
}
dependencies {
compile project(':native-activity')
}
One way to do this is to add it to your LOCAL_C_INCLUDES in Android.mk, like this:
LOCAL_C_INCLUDES += /path/to/ndk/sources/android/native_app_glue
Make sure the path is correct, by doing an ls on /path/to/ndk/sources/android/native_app_glue/native_app_glue.h
add these line in your cMakeList.txt file
//line1
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
//line2
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
also add native_app_glue in target_link_libraries.
It come in effect only after click on RUN or shift + F10
Add to cmake
include(AndroidNdkModules)
android_ndk_import_module_native_app_glue()
target_link_libraries(
native_app_glue
)