include*.so file at jnLibs to Android Studio for spatiallite libjsqlite - android

I want to add *.so library to my existing project. But the *.so file isn't found. Android Studio colored the data brown.
I added the Files like this:
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86
|--|--|--|--|--|--.so Files
build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.xxx.xxxx"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "5g"
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar','.so'])
compile 'me.dm7.barcodescanner:zbar:1.9'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:25.1.0'
compile 'com.qozix:tileview:2.2.6'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.2'
testCompile 'junit:junit:4.12'
}
I get this error:
java.lang.UnsatisfiedLinkError: No implementation found for void jsqlite.Database.internal_init() (tried Java_jsqlite_Database_internal_1init and Java_jsqlite_Database_internal_1init__) at jsqlite.Database.internal_init(Native Method)
If I look into my unpacked APK, I see librarys for arm64-v8a, mips, mips64 and x84_64 where the libjsqlite.so is not available.

Update to address changes in question:
After your update to your question including the error you get and some googleing for jsqlite.Database.internal_init() I'd suggest you have a look at this question:
java.lang.UnsatisfiedLinkError in jsqlite.Database.internal_init in Android Spatialite
Original answer:
This is how I have it in my app:
*.so files in src/main/libs (in thier armeabi, x86 folder each)
|--app:
|--|--src:
|--|--|--main
|--|--|--|--libs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86
|--|--|--|--|--|--.so Files
and in my build.gradle
android {
// other configuration
sourceSets {
main {
jniLibs.srcDirs = ["src/main/libs"]
}
}
}

Related

specify .so files in build.gradle file android studio

This is my Directory Structure
src -main
-java
-jniLibs
-armeabi
-lib1.so
-lib2.so
Need to understand what piece of code should be written in build gradle file for these files to be included in the build.
Right now, i am getting the error of not finding the .so file.
java.lang.UnsatisfiedLinkError: nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libFPEComponent.so"
Following solution by H.Brooks
I have got to add here
My Git repository:
My bUild.gradle file
apply plugin: 'com.android.application'
android {
productFlavors {
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
sourceSets
{
main
{
jniLibs.srcDirs = ['src/main/jnilibs']
}
//Another code
}
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.goambee.biometricziqitza"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86, armeabi-v7a, and mips.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "armeabi-v7a"
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}
//task native-libstiveLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
// destinationDir file("$buildDir/native-libs")
// baseName 'native-libs'
// from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
// into 'lib/'
//}
//
//tasks.withType(JavaCompile)
// {
// compileTask -> compileTask.dependsOn(nativeLibsToJar)
// }
Here i have included source set block, i also had tested without that block.
So still build isn't able to access .so files.
If you want to use it you can call it in your class like this:
static {
System.loadLibrary("libSONAME");
}
Add the following in your gradle:
jniLibs.srcDirs = ['libs']
Edit:
Adding .so Library in Android Studio
Create Folder "jniLibs" inside "src/main/"
Put all your .so libraries inside "src/main/jniLibs" folder
Folder structure looks like,
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86
|--|--|--|--|--|--.so Files
No extra code requires just sync your project and run your
application.
Reference
https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main
Not sure what files you exactly have, if you only have .so?
Have a look at the image below:
This is a 'project/library' within my project and this is how the load the .so files get loaded/added:
I compile the project like this:
compile project(':videokit')

Packages from library module not found in main module

I got a project which I imported from Eclipse to Android Studio. In Eclipse everything worked well.
It contains a main module (a project in Eclipse) which uses packages from a library module (library project in Eclipse). Since the migration did not went well, I have created a library module manually and just copied all the source code to the newly created module.
The problem is that the main module doesn't seem to find the packages from the library module and when I rebuild the project I get errors like "package bla bla does not exist".
Here is the main module gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.pointer.mamagoose"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':linphoneclean')
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile files('libs/firebase-client-android-2.5.0.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/apache-httpcomponents-httpcore.jar')
compile files('libs/android-support-v7-recyclerview.jar')
}
linphoneclean is the library module.
The entire project's settings.gradle:
include ':linphoneclean'
include ':tigris'
This is the build.gradle of the library module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.6.2'
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/linphone.jar')
compile files('libs/firebase-client-android-2.5.0.jar')
}
The structure of the library module includes for example folder:
src/main/com/pointer/linphone (and inside there are all the java files with a deceleration of package com.pointer.linphone, Yet I still get an error saying >"package com.pointer.linphone does not exist).
What am I doing wrong?
After fighting with the same issue for hours here is what worked for me.
I've created a fresh project with blank activity, added a library module with a dummy class, defined the dependency. Verified that it works by importing the dummy class in the app. Then I copied all my relevant code from the real project.
My thinking is that it was probably issue with IDE's iml files, since starting from scratch and copying stuff over worked.
See properly source file contains both java folder and res folder,add java files in java packages and res in res folder.Add Activity name in Manifest file see here ,add necessary libraries files in Gradle file.Clean and rebuild the project in the Android studio.
https://developer.android.com/guide/topics/manifest/manifest-element.html
Maybe you can check if the library's AndroidManifest has defined the package correctly, like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.pointer.linphone">

How to set NDK_PROJECT_PATH in Android Studio

I am very new to NDK debugging and I am trying to build the cpp code for debugging.
This is how my Application.mk file looks :
APP_STL := stlport_static
APP_MODULES := abc xyz
APP_CFLAGS += -fno-rtti -fexceptions
APP_ABI := armeabi armeabi-v7a
NDK_TOOLCHAIN := arm-linux-androideabi-4.9
and I an getting the following error , I have tried all the toolchains in ndk tools , what am I missing ?
update:
I realized that NDK_PROJECT_PATH is set to null , when built is run from Android studio. I am able to run
ndk-build -C from the terminal.
Actually my ultimate aim is to be able to debug native c++ files , by setting break points.
So current scenario:
I have native code in xyz folder with has jni folder containing android.mk and application.mk
I can run ndk-build in this folder and get the .so files, which I manually copy paste in jnilibs folder of the my android app (say appB):
This is the gradle of the appB :
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 13
targetSdkVersion 13
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile 'junit:junit:4.12'
// compile 'com.android.support:appcompat-v7:24.1.1'
}
Later I use this app as dependency in another app say appA.
This is the gradle of appA:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "*****"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories{
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:preference-v14:24.1.0'
compile project(':appB')
}
I need to be able to debug,
appA (which I can)
appB (which I can)
native code included as .so in appB (which I dont know yet how to)
aap
You can update the Android Studio to 2.2.2, and use the menu File-> Link C ++ Project with Gradle.
The official ndk samples can be found here!
There will be a local.properties files in your project folder from where the sdk & ndk paths can be configured. Normally the file has sdk directory path, you can configure your ndk path using keywork ndk.dir. For example
sdk.dir=YOUR_PATH_TO_SDK ( sdk.dir= /home/Android/Sdk)
ndk.dir=YOUR_PATH_TO_SDK ( ndk.dir= /home/Android/Sdk/ndk-bundle)

Create pre build event to copy files to assets folder in Android application

I have this project structure:
ProjectFolder/IosFolder,AndroidFolder,CommonFolder
Now android app uses files from it's assets folder.
But we decide to make Common folder for the same files.
Could you help me to make function witch will copy files from Common folder(this folder is under my project, so in Android Studio I don't see it) to android assets folder before app will be built?
In Common folder will be some .json files and font files.
As I understand, i need to write this function in my build.gradle file
something like that:
task copyFiles(type: Copy)
copyFiles {
description = 'Copy files'
from 'Common/'
into 'Android/{projectName}/app/src/main/assets'
}
Here is my file:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "amc.amc_mobile_promo2"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
//For Flurry
multiDexEnabled = true
}
//For Flurry
/*compileOptions {
//noinspection GroovyAssignabilityCheck
sourceCompatibility JavaVersion.VERSION_1_7
//noinspection GroovyAssignabilityCheck
targetCompatibility JavaVersion.VERSION_1_7
}*/
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'joda-time:joda-time:2.8.2'
compile 'com.github.orangegangsters:swipy:1.2.0#aar'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.6.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.6.0'
/*compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'*/
}
And could you tell me where can i see results of executed methods in Gradle Console?
What path i need to use and where in build.gradle file situate this method?
Hope you will help me.
Can you try this configuration:
gradle.projectsEvaluated {
preBuild.dependsOn(copyFiles)
}
update:
there are many commands the copy task can do for you. from the docs here are examples:
task anotherCopyTask(type: Copy) {
// Copy everything under src/main/webapp
from 'src/main/webapp'
// Copy a single file
from 'src/staging/index.html'
// Copy the output of a task
from copyTask
// Copy the output of a task using Task outputs explicitly.
from copyTaskWithPatterns.outputs
// Copy the contents of a Zip file
from zipTree('src/main/assets.zip')
// Determine the destination directory later
into { getDestDir() }
}
if you just want to copy from one source directory to another you can do this :
task copyFiles(type: Copy) {
from 'pathToMyAssets'
into 'AndroidStudioAssetsFolderPath'
}
UPDATE do this in your app's build.gradle at the very bottom:
task copyFiles(type: Copy) {
from 'Users/kostya/repo_amc_mobile_promo/Common/'
into 'Users/kostya/repo_amc_mobile_promo/Android/AMC_Mobile_Promo2/app/src/main/assets'
}
preBuild.dependsOn(copyFiles)
According to documentation here's how to copy a file via gradle:
task myCopyTask(type: Copy) {
from file("${buildDir}/reports/my-report.pdf")
into file("${buildDir}/toArchive")
}
To do it before build you must add the following line:
preBuild.dependsOn(myCopyTask)
You can use absolute or relative path that may use some of the project properties. To ensure path of project properties do not hesitate to print it using :
println file('${buildDir}')

Java.lang.UnsatisfiedLinkError: couldn't find "libstlport_shared.so

I am very new to SQL Cipher. I read many stuff and implemented SQLCipher into my project.
I have put below JAR files into app/src/libs
commons-codec.jar
guava-r09.jar
sqlcipher.jar
sqlcipher-javadoc
I have put below file into app/src/main/assets
icudt46l.zip
I have put below file into app/src/main/jniLibs
In Folder: armeabi
libdatabase_sqlcipher.so
libsqlcipher_android.so
libstlport_shared.so
In Folder: armeabi-v7a
libdatabase_sqlcipher.so
libsqlcipher_android.so
libstlport_shared.so
In Folder: x86
libdatabase_sqlcipher.so
libsqlcipher_android.so
libstlport_shared.so
Below my gradle file in android studio.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "abc.com.sqlcipher"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
After this, i run my application and it gets crash every time with below error.
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/abc.com.sqlcipher-1/base.apk"],nativeLibraryDirectories=[/data/app/abc.com.sqlcipher-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "liblibstlport_shared.so"
After 4 to 5 hours, i got the solution from one of my friend.
Write below code into build.gradle file before android{} block.
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
}
Write below line into dependencies {} block.
compile 'com.commonsware.cwac:sqlcipher-for-android:3.3.1'
Now you Sync your project then you can use SQL-Cipher Database into your application eaisly.

Categories

Resources