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.
Related
I am working on creating an AAR which is downloaded by the build server at compile time, it will contain a C++ pre compiled library, which will have the .so files within it. I have already got the c++ and the AAR with the respective files completed. I am not however able to consume it by my simple test application made for testing the library.
Clearly the issue is I have not told the project how to link the contents of the AAR in a way the JNI can load it. I just cant seem to find out how one is to use these AAR files for .so resources, which is a hard requirement. It is as if after it compiles with the implementation project that it is missing the /jni folder (which is clearly in its compressed contents)
I confirmed I have the .so files in the AAR with a plugin. It shows
-jni
-x86
libmyproject.so
-armeabi-v7a
libmyproject.so
in addition the other lib/res/assets etc that I do not care about.
Running my project I see the expected files in build/aar with myproject-Android-release and build/aar-debug with myproject-Android-debug.aar. Which is where I want them.
In my settings.gradle I have
include ':myproject-Android-debug',':myproject-Android-release'
In my build.gradle I have
import xxx
buildscript {
apply plugin: 'xxxx'
dependencies {
classpath brazil.tool('AndroidGradle', 'AndroidSDK', 'KotlinGradlePlugin', 'xxxx')
}
}
apply plugin: 'xxx'
apply plugin: 'xxx-android-sdk'
apply plugin: 'com.android.application'
apply plugin: 'xxx-android'
configurations {
ktlint
}
dependencies {
implementation brazil.build()
testImplementation xxx.testbuild()
ktlint brazil.tool('Ktlint')
implementation project(":myproject-Android-debug")
}
android {
compileSdkVersion SDK.platformVersion.toInteger()
buildToolsVersion SDK.buildToolsVersion
defaultConfig {
applicationId "com.company.testapp"
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
// let gradle pack the shared library into apk
//possibly here?
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude "/META-INF/proguard/**"
}
}
task ktlint(type: JavaExec) {
inputs.files(project.fileTree(dir: "src", include: "**/*.kt"))
outputs.dir("${buildDir}/reports/ktlint/")
group = 'verification'
main = "com.github.xxxx"
classpath = configurations.ktlint
args = [
"--reporter=plain",
"--reporter=checkstyle,output=${buildDir}/reports/ktlint/ktlint-report.xml",
"src/**/*.kt"
]
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec) {
group = 'verification'
main = "xxx"
classpath = xxx
}
Crash output
2020-04-24 01:20:57.150 10387-10387/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.company.testapp, PID: 10387
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/base.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.company.testapp-4-XMV-9aZlJXyboIRl92bA==/lib/x86, /system/lib]]] couldn't find "libmyproject.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
at java.lang.System.loadLibrary(System.java:1669)
at com.company.project.MainActivity.<clinit>(MainActivity.kt:33)
i am trying to access to some hikvision cctv cameras.
I have got the so files and the jar files.
when i try to run the program it says
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/idonic.mobileapp.androidhikvision-1/base.apk"],nativeLibraryDirectories=[/data/app/idonic.mobileapp.androidhikvision-1/lib/arm, /data/app/idonic.mobileapp.androidhikvision-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libMPCtrl.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at org.MediaPlayer.PlayM4.Player.<clinit>(Player.java:775)
at idonic.mobileapp.androidhikvision.PlayBackByTime$LoadingDevicesTask.doInBackground(PlayBackByTime.java:80)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
The error occurs when i try to call
player = Player.getInstance();
this is the current structure of my program
The error says it cannot find the path in some folder that is not my project so i think i am missing some thing.
maybe i need to declare the new folder where the so files are located.
this is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "idonic.mobileapp.androidhikvision"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
jni.srcDirs = [] //disable automatic ndk-build
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/HCNetSDK.jar')
compile files('libs/PlayerSDK.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
I am testing in a xiaomi redmi note 4 with android 6/MIUI8.5.3.0.
The gradle version is 2.3 and android studio is 3.0.
i have try to load the project in other devices and in the device with android 5.0 the code works and i can see image from the cctv camera.
the other devices were and s7 with android 7.1.
What i am missing....
Thanks in advance..
I was facing the same problem after using the latest Android version > 25. Here is how i fixed the problem.
create three folder under app/jniLibs
a. app/jniLibs/x86
b. app/jniLibs/armeabi
c. app/jniLibs/armeabi-v7a
As shown in the picture below
Add folders
Create a gradle.properties file under rood folder. Right click on the root of the folder, which would be 99% app folder > New file > name it gradle.properties
Paste the following line
android.useDeprecatedNdk=true -> gradle.properties
Add following lines inside build.gradle(Module: app)
android{
....
defaultConfig{
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi"
}
....
}
Run the app with you finger crossed.
I also got into this problem, and I had to add also this in App Manifest file:
<application
android:extractNativeLibs="true" ...
Always use the last technical advice: keep you finger crossed.
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)
Android Studio 1.1 generated apk file (located # app/build/outputs/apk folder) contains the lib directory, and for every cpu type there exists a non-empty folder, like /x86. Each of these folder contain a libapp.so shared library that is around 5Kb in size per cpu.
I've searched the net and the only thing I found so far is this link from Intel https://software.intel.com/en-us/articles/building-native-android-apps-using-intelr-c-compiler-in-android-studio that shows how to change the default libapp.so to user-provided library.
So, I guess that this library (libapp.so) is somehow built by gradle.
In fact I do my own native library building, using ndk-build command line tool, and my libs are placed alongside that libapp.so. It's not causing any issues btw, but I feel that I'm losing the control over what is built and why.
Here's my humble build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
/**
* Path to *.so files
*/
sourceSets {
main {
jniLibs.srcDirs = ['src/main/libs']
jni.srcDirs = [] //disable automatic ndk-build
}
}
defaultConfig {
applicationId "com.sample.android"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
How can I disable this libapp.so being built?
defaultConfig {
ndk {
moduleName "yourSelfLib"
}
}
I'm writing a Google Glass application. I'm using a third-party library that consists of some assets (and instructions to place them in the assets/ dir), some jars (and instructions to place them in the libs/ dir) and a .so (and instructions to place it in libs/armenabi-v7a/).
When I run the application, I get an UnsatisfiedLinkError, it appears the .so isn't being included. Unzipping the apk corroborates this, I don't see the .so anywhere there.
java.lang.UnsatisfiedLinkError: Couldn't load nameofsofile_jni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.package.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.package.demo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:529)
at <Calls inside the external library>
My build.gradle:
apply plugin: 'com.android.application'
repositories {
jcenter()
flatDir {
dirs 'prebuilt-libs'
}
}
android {
compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.package.demo"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('src/main/libs/jarone.jar')
compile files('src/main/libs/jartwo.jar')
compile files('src/main/libs/jarthree.jar')
}
How do I get it to include the .so?
By default in Android Studio, you .so files should be placed in src/main/jniLibs/ rather than src/main/libs/. I don't see a reason for you to change this, but it is possible with the following code added to the android{} part of your build.gradle file.
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}