Android Library: .so not packed with module - android

Previously I had two Android Studio projects. One is using some shared library placed in /src/main/jniLibs (lets call that project bmf). The second project is my actual library which is using that other project (bmf) as an .aar.
If some application is now using the library I had to add the project with the shared library (bmf) as well because the .so files were not packed. Because I want to merge the two projects to one library project I have imported the bmf project as a module. Now if I assemble the library, the .so file of the module is not included. How can I fix that?
My app-module build script looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 15
buildToolsVersion "26.0.2"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
implementation project(':pbJavaBmf')
}
My bmf-module build script looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 15
buildToolsVersion "26.0.2"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
task buildNative(type: Exec, description: 'Pack .so with module') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'V=1',
'NDK_DEBUG=1',
'NDK_LIBS_OUT=../jniLibs'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:18.0.0'
}

Related

Execution failed for ':app:ndkBuild'. Process 'command ndk-build.cmd' finished with non-zero exit value 2

I have been stuck on this problem for 2 days and have tried out all possible solutions given on stackoverflow. Below is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDir 'src/main/libs'
defaultConfig {
applicationId "com.example.anannyauberoi.testingcam"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
moduleName "app"
cFlags "-std=c++11 -fexceptions"
ldLibs "log"
stl "gnustl_shared"
abiFilter "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = []
res.srcDirs = ['src/main/res']
jniLibs.srcDirs=['src/main/libs']
} }
//sourceSets.main.jni.srcDirs = []
// disable automatic ndk-build call, which ignore our Android.mk
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:/Users/Anannya-Uberoi/AppData/Local/Android/sdk/ndk-bundle/ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
tasks.all { task ->
if (task.name.startsWith('compile') && task.name.endsWith('Ndk')) {
task.enabled = false
}
}
// call regular ndk-build(.cmd) script from app directory
}
//Modify the below set of code to the ndk-build.cmd location in your computer.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':openCVLibrary249')
}
I have already tried all possible solutions- deleting the obj folder in the build folder, trying to avoid automatic Android.mk call by setting the sourceSets.main, trying to avoid the compileDebugNdk task from getting called. I also do not have any cmake.txt files. I cannot seem to get over the problem.
I have used Android Studio 2.3.2 and 2.1.1 and the problem has persisted in both of them.
Any help would be appreciated.
You should use the latest Android Studio, 2.3.2 is OK. It has integrated externalNativeBuild in android gradle plugin, so you don't need the tricks with custom gradle task.
I could not actually test the build.gradle script below, so please forgive me any typos:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.anannyauberoi.testingcam"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
targets "app"
cppFlags "-std=c++11 -fexceptions"
arguments "APP_STL=gnustl_shared"
abiFilters "armeabi-v7a"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main {
res.srcDirs = ['src/main/res']
} }
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
//Modify the below set of code to the ndk-build.cmd location in your computer.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':openCVLibrary249')
}
I went to:
C:\Users\Dev\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd
directory and for the ndk-build.cmd i press
Right-Click> Edit and change the cmd file from:
#echo off
%~dp0\build\ndk-build.cmd %*
to
#echo off
THAT works for me

How to fix NDK build error in AndroidStudio

I want build my project from AndroidStudio into my phone, but when run button in Android Studio. show me this error :
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Build.Gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 14
targetSdkVersion 23
ndk {
moduleName "player_shared"
}
}
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')
}
How can i fix it?
paste below code in your build.gradle(Module:app)
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}
Paste this in build.gradle above buildTypes{}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}

Android Studio generated signed apk issue Gradle

I'm trying to export a signed apk of my exported project from eclispe ADT to Android Studio.
I have 2 issues:
Error:(16, 0) Gradle DSL method not found:
'lintOptions()'
Possible causes:The project 'gigCheck2' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
And when I'm trying to generate the apk:
Missing Gradle Project Information. Please check if the IDE
successfully synchronized its state with the Gradle Project
Model.
I've two build.gradle
1-Inside root project:
<code>// 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:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}</code>
2-In the app
<code>
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.project.client.android"
minSdkVersion 7
targetSdkVersion 10
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
sourceSets {
main {
manifest.srcFile 'app/src/main/AndroidManifest.xml'
}
}
}
dependencies {
compile files('lib/commons-codec-1.7.jar')
compile files('lib/commons-io-2.4.jar')
compile files('lib/commons-lang-2.6.jar')
compile files('lib/core.jar')
compile files('lib/javase.jar')
compile files('lib/ksoap2-android-assembly-3.0.0.jar')
}
</code>
Remove lintOptions in root level gradle file and add it in app level gradle file.
Your app>build.gradle look like this.
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.project.client.android"
minSdkVersion 7
targetSdkVersion 10
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
sourceSets {
main {
manifest.srcFile 'app/src/main/AndroidManifest.xml'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile files('lib/commons-codec-1.7.jar')
compile files('lib/commons-io-2.4.jar')
compile files('lib/commons-lang-2.6.jar')
compile files('lib/core.jar')
compile files('lib/javase.jar')
compile files('lib/ksoap2-android-assembly-3.0.0.jar')
}
lint options should be included in your module gradle not project:
android{
defaultConfig {
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
}

How to include Android libraries and classes for Sonar?

I try to use last SonarQube plugin for Gradle on an Android project.
I follow this:
http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle
My root.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
plugins {
id "org.sonarqube" version "2.0.1"
}
allprojects {
repositories {
jcenter()
}
}
My app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxxxxx.xxxxxx"
minSdkVersion 15
targetSdkVersion 17
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 232
versionName "2.3.2"
}
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
testOptions {
unitTests.returnDefaultValues = true
}
}
sonarqube {
properties {
property "sonar.projectName", "xxxxx"
property "sonar.projectKey", "org.sonarqube:com.xxxxxxx.xxxxxxxx"
property "sonar.sources", "src/main/java"
property "sonar.java.binaries","build/intermediates/classes"
property "sonar.tests", "src/test/java"
property "sonar.android.lint.report", "build/lint-results.xml"
property "sonar.junit.reportsPath", "build/test-results/debug/"
}
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
I run
./gradlew sonarqube -Dsonar.verbose=true
Logs:
Incremental java compilation is an incubating feature.
:sonarqube
Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin, please use sonar.java.binaries and sonar.java.libraries instead
Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
Class 'com/xxxxxx/xxxxxxx/ChangelogActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ChangelogActivity$1' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity$1' is not accessible through the ClassLoader.
I obtain this error msg on all my classes.
Unfortunately due to complexity of Android Gradle projects (ability to have several flavors in a single project for example) we are not able to automatically collect all information we need to run a SonarQube analysis without any extra config.
Please follow: https://jira.sonarsource.com/browse/SONARGRADL-6

how to import libraries to android studio? (Android manifestmerger file)

I know this sounds very easy, but android studio is eating my brains out. I know how to import my current project say myProject in to ADT very easily. But I came to know that soon the support for adt will be ending. So i decided to switch to Android studio. I am using the following libraries in my project
Commons
ActionBarSherlock
AndroidImageChacheMaster
SlidingMenuMaster
I tried to import the project myProject.
See its Project.Properties file
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-21
android.library.reference.1=../actionbarsherlocklibrary
android.library.reference.2=../Android-Image-Cache-master
android.library.reference.3=../Commons
android.library.reference.4=../google-play-services_lib
android.library.reference.5=../SlidingMenuMaster
When i tried to import it A.S told me unrecoverable errors and I pasted the library folder as instructed by android studio.
And it project was imported succesfully
but there are two error apparing in the log
/home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/manifests/tmp/manifestMerger2026412193483179673.xml
Error:(5, 5) uses-sdk:minSdkVersion 5 cannot be smaller than version 7 declared in library /home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/exploded-aar/com.actionbarsherlock/actionbarsherlock/4.4.0/AndroidManifest.xml
Error:(5, 5) Execution failed for task ':commenorkingandroid:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 5 cannot be smaller than version 7 declared in library /home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/exploded-aar/com.actionbarsherlock/actionbarsherlock/4.4.0/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.actionbarsherlock" to force usage
please help what is wrong here?
and now my project structure is
actionbarsherlocklibrary(empty)
myProject(manifests,java,res,aidl,resources,c,assets)
androidimagecachemaster(manifests,java,res)
commenorkingandroid(manifests,java,res) // i havent imported anything with this name
commons(manifests,java,res)
Gradle Scripts
build.gradle(Project:myProject)
build.gradle(Module:actionbarsherlock)
build.gradle(Module:myProject)
build.gradle(Module:commons)
build.gradle(Module:androidimagecachemaster)
build.gradle(Module:commenorkingandroid)
gradle-wrapper.properties
settings.gradle
here are my gradle files
build.gradle(Project:myProject)
// 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:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle(Module:actionbarsherlock)
apply plugin: 'java'
build.gradle(Module:myProject)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.five.myApp"
minSdkVersion 11
targetSdkVersion 16
ndk {
moduleName "cr3engine-3-1-1"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':actionbarsherlocklibrary')
compile project(':androidImageCachemaster')
compile project(':commons')
compile project(':commenorkingandroid')
compile 'com.google.code.gson:gson:2.1'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-io-2.4.jar')
compile files('libs/epublib-core-latest.jar')
compile files('libs/slf4j-android-1.6.1-RC1.jar')
compile files('libs/slf4j-android-1.7.5-7-sources.jar')
compile files('libs/universal-image-loader-1.9.1.jar')
compile files('libs/zip4j_1.3.2.jar')
}
build.gradle(Module:commons)
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/actionbarsherlock-plugin-maps-4.1.0.jar')
}
build.gradle(Module:androidimagecachemaster)
apply plugin: 'com.android.library'
android {
compileSdkVersion 10
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/CWAC-AdapterWrapper.jar')
}
build.gradle(Module:commenorkingandroid)
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 5
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
}
If you have added Sherlock as an AAR dep like
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
you can remove
compile project(':actionbarsherlocklibrary'), include ':sherlock' line from your settings.gradle, then related folder from your project.
And your targetSdkVersion can be the same as your compileSdkVersion as well.

Categories

Resources