How to use .so files in Android - java

I am tring to add a C++ library into my Android project, but I keep getting the error:
Could not get unknown property 'jniLibs' for source set 'main' of type org.gradle.api.internal.tasks.DefaultSourceSet.
The project attempts to use a .so library of SQLite ( amalgamation).
How can I include the .so lib in my project and link it successfully to be able to call its functions?
Thank you all in advance.
My build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
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'
}
}
productFlavors {
}
buildToolsVersion '27.0.3'
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}

remove config in build.gradle. This path is the default value of jniLibs, no customer config is needed.
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
or try with this config
sourceSets {
main {
jniLibs.srcDir(['src/main/jniLibs'])
}
}
copy the so file into app/src/main/jniLibs.
add the JNI java interface jar into your dependency.
System.LoadLibrary(libName) // for example you put xxx.so into jniLibs folder. here would be System.LoadLibrary("xxx")
Use the native method in JNI java class to call so method.

Related

'provided' is obsolete but where is the provided

apply plugin: 'com.android.application'
apply plugin: 'net.saliman.cobertura'
android {
compileSdkVersion 26
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "ch.zhaw.facerecognition"
minSdkVersion 21
targetSdkVersion 26
versionCode 28
versionName "1.5.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
cobertura {
coverageFormats = [ 'html', 'xml' ]
}
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.4.0'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
api 'com.android.support:appcompat-v7:26.0.0'
api 'com.android.support:support-v4:26.0.0'
api 'ch.zhaw:facerecognitionlibrary:1.5.3'
}
The compiler is android studio.
Above is my build file after I build it the compiler told me that Configuration 'provided' is obsolete and has been replaced with 'compileOnly'.
But where is the provided?
Replace "api" with "implementation" and your issue will be solved, like this:
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support:support-v4:26.0.0'
implementation 'ch.zhaw:facerecognitionlibrary:1.5.3'

Unable to merge dex Android Studio 3.0.1

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Just after updating Android studio 3.0.1 recently from 2.3.3 version, I am facing issue related to DexMergerException.
Someone else also posted question-related to this. But in this question, I want to analyze the stack trace to find the related solution(since I am a newbie here..).
I am unable to resolve it.
This is my build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.aimnatvtz.aimatv"
manifestPlaceholders = [onesignal_app_id: "MY_ONESIGNAL_APP_ID",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "226589149887"]
minSdkVersion 16
targetSdkVersion 27
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
google()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}
}
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:design:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'it.sephiroth.android.library.easing:android-easing:+'
implementation 'com.facebook.android:facebook-login:4.27.0'
implementation 'com.android.support:recyclerview-v7:27.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.bumptech.glide:glide:4.0.0'
implementation 'com.google.android.gms:play-services-auth:11.6.2'
implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
implementation 'com.onesignal:OneSignal:[3.6.2, 3.99.99]'
implementation 'com.paypal.sdk:paypal-android-sdk:2.15.3'
testImplementation 'junit:junit:4.12'
}
Tried to enable multidex
modify your build.gradle
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
defaultConfig {
multiDexEnabled true
}
in your manifiest file define your apllication name properrty like this
android:name="com.pkg.YouApplication"
Include this in your Application class
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
I had the same problem, it is associated with the update
compile 'com.google.android.gms: play-services: 11.4.2 to compile' com.google.android.gms: play-services: 11.6.0
Return back to the old version of the play-services

Failed to resolve Ksoap2

I have a problem with Android Studio saying:
failed to resolve
com.google.code.ksoap2-android:ksoap2-android:3.6.1
Here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.papiroomdemo.webservicetest"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
repositories {
maven { url 'http://ksoap2-android.googlecode.com/svn/m2-repo' }
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.hannesdorfmann.smoothprogressbar:library:1.0.0'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.0'
}
Error:(30, 13) Failed to resolve:
com.google.code.ksoap2-android:ksoap2-android:3.6.1 Show in FileShow in Project Structure
dialog
I think your url in repositories section is invalid. You should add
https://oss.sonatype.org/content/repositories/ksoap2-android-releases/:
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
More info here: http://simpligility.github.io/ksoap2-android/getting-started
/// add these lines in module gradle
allprojects {
repositories {
google()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'
}
}
}

Java\jdk1.7.0_06\bin\java.exe'' finished with non-zero exit value 1 android studio

I am getting this error while i run program in the Android studio.. There is no anyother is here i guess.
Error:Execution failed for task ':app:createDebugMainDexClassList'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_06\bin\java.exe'' finished with non-zero exit value 1
Here it is my gradle file copy..
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "app.example.com"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions { abortOnError false }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/socialauth-4.9.jar')
compile 'com.android.support:recyclerview-v7:+'
compile project(':linkedin-sdk')
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'org.lucasr.twowayview:twowayview:0.1.4'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:design:+'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile ('org.apache.httpcomponents:httpmime:4.3.5')
{
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
}
what's the issue ?
its seems to be multidex issue. just add maximum heap size and multidex library dependency.
android {
dexOptions {
incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
defaultConfig {
multiDexEnabled true
}
also put Dependency
compile 'com.android.support:multidex:1.0.0'
you will also need to extend your application class to MultiDexApplication
public class App extends MultiDexApplication {
#Override
public void onCreate()
{
super.onCreate();
// Initialize
}
#Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Don't forgot to make an entry of app class in manifest.
Use this in app build.gradle worked for me
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}

Android Studio 2.2 Native debugging of submodule (library)

I can't use LLDB for JNI C code debugging. None of the breakpoints hit, and I can't even get into C code with debugger.
Gradle files:
project-gradle:
// 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.2.2'
// 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
}
app-module-gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "co.bstorm.pazljivko"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions -std=c++11"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/']
}
}
}
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 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
testCompile 'junit:junit:4.12'
debugCompile project(':signrecognizer')
}
signrecognizer-module-gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions -std=c++11 -D_DEBUG"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
}
configurations {
debug
release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
jniDebuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "../CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/']
jniLibs.srcDirs = ['../lib']
}
}
}
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 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
compile project(':openCVLibrary310')
}
My signrecognizer module is using OpenCV with CMake files. They all build successfuly, but i can't access those units too.

Categories

Resources