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'
}
Related
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.
I'm a newbie with gradle and I'm having a dependecy problem. I have the follow project structure:
-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar
Both MyAppPro and MyAppFree depend on MyAppLibrary, which depends on ThirdPartyLibraryWrapper. As the name suggests, ThirdPartyLibraryWrapper is a wrapper on an external library, namely ThirdPartyLibrary.aar.
This is my configuration:
build.gradle MyAppPro
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':MyAppLibrary')
}
build.gradle MyAppLibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}
build.gradle ThirdPartyLibraryWrapper
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
}
When gradle sync completes, I have got this error:
MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
Can someone help me figure out where is the issue?
The other projects are seeing that the :ThirdPartyLibraryWrapper project depends on an artifact called ThirdPartyLibrary-0.1.0:aar. Java (and Android) libraries do not bundle their own dependencies together - instead, they simply publish a list of their dependencies. The consuming project is then responsible for loading not only the library it directly depends on, but all of the libraries that library depends on.
The net effect of this is that :MyAppFree is loading in :ThirdPartyLibraryWrapper, then seeing that :ThirdPartyLibraryWrapper depends on ThirdPartyLibrary-0.1.0:aar and so thus trying to load that in as well. However, :MyAppFree doesn't know where ThirdPartyLibrary-0.1.0:aar lives.. and so it fails.
The solution will be to place similar repositories blocks in all your other projects. Try this:
repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}
Using the project(...).file(...) method will free you from having to hardcode paths, and will instead use the Gradle DSL to resolve the filesystem path by looking up the project and having it do the resolution dynamically.
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 want to use this library in a project in Android Studio, so as mentioned in read me, I created new project in the Android Studio and added dependencies in build.gradle file inside the app folder as:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.swipe_instagram"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.lorentzos.swipecards:library:1.0.8#aar'
}
Then when I sync I started getting this error as:
I have Searched on the google and stack overflow but can't find any appropriate solution.
I used your "build.gradle" file and it is working fine for me (both with and without "aar"). Could be something wrong with the cache. Try "File -> Invalidate Caches / Restart"). Another way to generate more error message detail is to try building the module from the command line and getting verbose output
gradle -info compileDebugSources
You'll get lots of output which should give you a hint as to what's going wrong
I'm getting these errors when trying to use an external library imported (as a Maven file dependency) through the Project Structure > Dependencies window in Android Studio 1.0 RC 2:
W/dalvikvm﹕ Unable to resolve superclass of Lcom/melnykov/fab/FloatingActionButton$1; (1487)
W/dalvikvm﹕ Link of class 'Lcom/melnykov/fab/FloatingActionButton$1;' failed
My build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "user.appname"
minSdkVersion 18
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: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:cardview-v7:21.0.2'
compile 'com.melnykov:floatingactionbutton:1.1.0'
}
I've googled around and most solutions are for projects in Eclipse, involving setting the Java Build Path to Order and Export, but I can't seem to find a similar setting in Android Studio.
Thanks!
Given that you added
repositories {
mavenCentral()
}
to your build.gradle, I think that your issue is caused by gradle not being able to reach external resources.
Are you behind a proxy?
I solved this problem adding file gradle.properties in my home .gradle directory. It's made like this:
systemProp.http.proxyHost=myproxy.mydomain.it
systemProp.http.proxyPort=myproxyport
systemProp.http.proxyUser=myproxyuser
systemProp.http.proxyPassword=XXXXXXXX
systemProp.https.proxyHost=myproxy.mydomain.it
systemProp.https.proxyPort=myproxyport
systemProp.https.proxyUser=myproxyuser
systemProp.https.proxyPassword=XXXXXXXX
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost