I'm developing an application for a device that has an SDK for itself.
When I try to import its SDK as a library in my application I will get an error like below:
E/MultiWindowProxy: getServiceInstance failed!
E/MultiWindowProxy: getServiceInstance failed!
E/AndroidRuntime: FATAL EXCEPTION: Thread-571
Process: cards.mena.app, PID: 9484
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/cards.mena.app-2/base.apk"],nativeLibraryDirectories=[/data/app/cards.mena.app-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libserial_port.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at android_serialport_api.SerialPort.<clinit>(Unknown Source)
at com.rt.printerlibrary.driver.serialport.ComDriver.a(Unknown Source)
at com.rt.printerlibrary.driver.serialport.ComDriver.run(Unknown Source)
I put the .Jar file and .so into libs folder in my application like below:
And this is my Gradle file:
android {
compileSdkVersion 28
defaultConfig {
applicationId "cards.mena.app"
minSdkVersion 21
targetSdkVersion 28
versionCode 10002
versionName "1.0.2"
setProperty("archivesBaseName", "MenaCards-v$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
sourceSets {
main {
// manifest.srcFile 'AndroidManifest.xml'
jniLibs.srcDirs = ['libs']
// java.srcDirs = ['src']
// resources.srcDirs = ['src']
assets.srcDirs = ['assets']
}
}
}
androidExtensions {
experimental = true
}
kapt {
generateStubs = true
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko-commons:0.10.8"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.android.support:design:$supportLibraryVersion"
/*----------------/ Printer Libs \---------------------------*/
implementation files('libs/printer_library_ap02.jar')
Update:
I downgrade my Gradle form 3.5.0 to 2.3.2 and my application is working now!
Then the problem is Gradle! What I have to do with that?
I found the problem and its answer.
The problem was about Gradle version and I had to add this line:
defaultConfig {
ndk {
abiFilters 'armeabi'
}
}
I put my .so files in src > main > jniLibs and there in the architecture dependent subfolders arm64-v8a, armeabi-v7a, ... . Don't need additional configuration then. May be this helps you.
I found the solution, you don't have to as a gradle dependency add it in the gradle app file.
android{
sourceSets {
main {
jniLibs.srcDirs = ['libs']
assets.srcDirs = ['assets']
}
}
}
I had the same problem, as #Ehsan suggested it worked.
I would like to point out something though, you don't need to downgrade your gradle.
If you'd like to put your .so files in the libs folder then you'd need to add
sourceSets {
main {
jniLibs.srcDirs = ['libs']
assets.srcDirs = ['assets']
}
}
Its not necessary if you already added them in the jniLibs folder.
Then adding
defaultConfig {
ndk {
abiFilters 'armeabi'
}
}
made it all work out well.
Related
I got the source of a project (An android application) from github and I am trying to launch it, the project is called "RtkGps+" it's an Anroid application to that use a C++ libary called Rtklib to play with GPS and Raw measurements.
My Android environment configuration is bellow,
Gradle version : 3.1.3
NDK revision : 19.0.5232133
I'm unable to compile the project, I got the errors bellow :
As shown in the the capture there are many errors, that I want to enumate them,
So the first one is this error where the NDK_PROJECT_PATH=null
SIMPLE: Error while executing process C:\Users\Yazid\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Yazid\Documents\Dev\Android\RtkGps-master\RtkGps-master\jni\Android.mk NDK_APPLICATION_MK=C:\Users\Yazid\Documents\Dev\Android\RtkGps-master\RtkGps-master\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-21 NDK_OUT=C:/Users/Yazid/Documents/Dev/Android/RtkGps-master/RtkGps-master/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=C:\Users\Yazid\Documents\Dev\Android\RtkGps-master\RtkGps-master\build\intermediates\ndkBuild\release\lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
The second one is saying that the Android.mk file is not supported
SIMPLE: Android NDK: WARNING: Unsupported source file extensions in C:\Users\Yazid\Documents\Dev\Android\RtkGps-master\RtkGps-master\jni\Android.mk for module rtklib
I tried adding gradle code from this answer : https://stackoverflow.com/a/50707270/6306138
The Gradle file of the project.
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
implementation group: 'cz.msebera.android' , name: 'httpclient' , version: '4.4.+'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.google.gms:google-services:3.2.1'
implementation 'com.google.android.gms:play-services-gcm:11.0.4'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.karumi:dexter:5.0.0'
implementation 'ch.acra:acra:4.5.0'
implementation 'commons-net:commons-net:3.6'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.infstory:proguard-annotations:1.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
android {
sourceSets.main.res.filter.exclude '**/proj4/jniwrap/org/**'
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "gpsplus.rtkgps"
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
ndk {
abiFilters = []
abiFilters.add('armeabi-v7a')
abiFilters.add('x86')
abiFilters.add('x86_64')
abiFilters.add('arm64-v8a')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
}
// instrumentTest.setRoot('tests')
}
externalNativeBuild {
ndkBuild {
path 'jni/Android.mk'
}
}
packagingOptions{
doNotStrip '*/mips/*.so'
doNotStrip '*/mips64/*.so'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
debug {
debuggable true
jniDebuggable false
renderscriptDebuggable false
}
}
productFlavors {
}
}
Neither of the "errors" mentioned are errors. NDK_PROJECT_PATH=null is normal behavior for Studio, and the second is just a warning.
Without seeing your Android.mk or the full error message (the line immediately after the one you included tells you what went wrong) I can't tell you how to fix the warning, but like the warning says, one of your source files has an unrecognized extension so ndk-build didn't know how to build it.
Having an issue where the apk being generated by our Gradle build contains a bunch of unnecessary files inside a test/resources directory
Our application build gradle contains several local module dependencies which are built as android libraries.
I know there is packagingOptions field in Gradle but you can't exclude directories as far as I can tell. Excluding each file isn't an option. Anyway, I would like to know the root cause for this.
Application gradle build:
apply from: "${rootDir}/android_application.gradle"
dependencies {
compile project(':local-lib1')
//... etc
compile project(':local-libN')
testCompile libraries['junit']
}
android {
defaultConfig {
versionCode 1
versionName "1.0"
multiDexEnabled true
}
}
And android_application.gradle:
apply plugin: 'com.android.application'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
compileSdkVersion android_sdk_version
buildToolsVersion android_build_tools_version
defaultConfig {
minSdkVersion android_min_sdk_version
targetSdkVersion android_target_sdk_version
}
buildTypes {
}
}
All modules are structured like so:
module
|
--AndroidManifest.xml
--build.gradle
--assets/
--res/
--src
|
-- main/
| |
| --java/
| --resources/
|
-- test/
|
--java/
--resources/
Why are test/resources being included in apk? How can I exclude them?
Edit (to show lib gradle):
Example lib gradle:
apply from: "${rootDir}/android_library.gradle"
dependencies {
compile 'com.android.support:multidex:1.0.0'
// ...etc external deps
// test deps
testCompile libraries['logback-classic']
testCompile libraries['junit']
testCompile libraries['mockito-core']
// etc...
}
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
}
android_library gradle:
apply plugin: 'android-library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
compileSdkVersion android_sdk_version
buildToolsVersion android_build_tools_version
defaultConfig {
minSdkVersion android_min_sdk_version
targetSdkVersion android_target_sdk_version
}
buildTypes {
release {
}
}
}
I am building with gradlew.bat -x test build
The test/resources included in the apk contains all the files in the corresponding test/resources for each lib. The size of directory (uncompressed) is 10mb so adds unreasonable amount to size of overall apk.
Try the resource shrinking. As per Google Documentation: "The Gradle build system for Android supports
resource shrinking": the automatic removal of resources that are
unused, at build time, in the packaged app. In addition to removing
resources in your project that are not actually needed at runtime,
this also removes resources from libraries you are depending on if they are not actually needed by your application
android {
...
buildTypes {
test {
minifyEnabled true
shrinkResources true
...
}
}
}
Think I've solved the issue.
I had in app build.gradle and each library build.gradle:
android {
sourceSets {
main {
resources.srcDirs = ['src']
}
}
}
Changed to
android {
sourceSets {
main {
resources.srcDirs = ['src/main']
}
}
}
I guess gradle was taking every resources dir under src/ and merging them into one - http://tools.android.com/tech-docs/new-build-system/resource-merging
my app exceeding 64k methods so iam supposed to implement Multidex ,
initially i had problem as "local path doesnt exist" i fixed that problem ,now gradle generated classes1.dex and classes2.dex ,
but not working in lower than lollipop..it was working fine in lollipop since it has a native support .error says that "<1st activity> is not present in dex path"
after seeing some tutorials they said that have to do a change in 1.gradle 2.application class 3.manifest
i dont have much knowledge about application class ..kindly guide me thanks
note:this is an imported project from eclipse .
kindly check build.gradle file
apply plugin: 'com.android.application'
android {
defaultConfig {
compileSdkVersion 23
buildToolsVersion '23.0.1'
minSdkVersion 15 //lower than 14 doesn't support multidex
targetSdkVersion 23
}
dexOptions {
jumboMode = true
preDexLibraries = false
javaMaxHeapSize "2048M"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
productFlavors {
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:multidex:1.0.1'
}
You followed a tutorial that shows how you could add multi-dex support manually before Android gradle plugin had support for it. Since v0.14.0, all you need to do is to add:
android {
defaultConfig {
...
multiDexEnabled true
}
And you can choose one of three options to call the MultiDex code. From MultiDexApplication documentation:
Minimal MultiDex capable application.
To use the legacy multidex library there is 3 possibilities:
- Declare this class as the application in your AndroidManifest.xml.
- Have your Application extends this class.
- Have your Application override attachBaseContext starting with
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Don't forget to remove the afterEvaluate block from your build script.
Make sure you've read the official documentation.
I'm using Android Studio and AndEngine library and TexturePacker Extension using this link to setup:
Setting Up AndEngine with Android Studio
I'm getting that issue:
Error:Class org.andengine.BuildConfig has already been added to output. Please remove duplicate copies.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Diego\android-sdks\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\Diego\NEXT\Next\app\build\intermediates\dex\debug --input-list=C:\Users\Diego\NEXT\Next\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/andengine/BuildConfig;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:732)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.M...(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
1 error; aborting
I've tried everything. Cleaning project, deleting BuildConfig classes (they are created automatically in texturepacker library), excluding modules, reimporting third_party libraries... but nothing seems to fix it.
Here my build.gradle files:
App:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.zmaxstudios.next"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile project(':third_party:andengine')
compile project(':third_party:texturepacker')
}
AndEngine > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Texturepacker > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
dependencies {
compile project(':third_party:andengine')
}
How can remove duplicated BuildConfig files? Or what should I do to fix that?
Thanks
Your problem looks like it lies in your dependencies, something like this, in my case.
compile 'com.google.android.gms:play-services:6.5.87'// and here's the issue
The Google Play Services libraries can be quite large and when combining in a lot of third party libraries or some newer Google libraries, that can be redundancies as your experiencing. I ran into a similar issues when implementing Google Cloud Storage. Typically I now just include what I really need from the android support libraries, i.e.
compile 'com.google.apis:google-api-services-storage:v1-rev18-1.19.0'
compile 'com.google.http-client:google-http-client-jackson2:1.20.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
compile 'com.google.api-client:google-api-client-java6:1.20.0'
compile 'com.google.android.gms:play-services-maps:7.3.0'
compile 'com.google.android.gms:play-services-location:7.3.0'
can you please remove this line from dependencies I'm seeing here you are using two support libraries. clean and build your project
compile 'com.android.support:support-v13:21.0.3'
I've finally solved the problem, that it wasn't with support libraries. I was getting the problem form third_party libraries, because manifest file of texturepacker library had the same package of andengine following the steps in link provided in the question, so BuildConfig.java classes was being duplicated. Now, the manifest files are:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine" >
<application>
</application>
</manifest>
And texturepacker:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine.extension.texturepacker.opengl.texture.util.texturepacker" >
<application>
</application>
</manifest>
Hope that can be helpfull.
Thanks all the answers.
I have an issue to import mupdf library into my android application. The problem is that the program was running well last week, and I probably changed something in the code that don't load mupdf anymore. If I try to load a pdf file, I have a message with "-my application- has stopped". Here is the logcat error message :
2530-2530/com.efc.efcredader E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.artifex.mupdfdemo.MuPDFActivity.openFile(MuPDFActivity.java:944)
at com.artifex.mupdfdemo.MuPDFActivity.onCreate(MuPDFActivity.java:710)
[...]
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load mupdf: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.artifex.mupdfdemo.MuPDFCore.<clinit>(MuPDFCore.java:16)
[...]
I call the libmupdf.so like that :
static {
System.loadLibrary("mupdf");
}
I've followed a lot a tutorials about how to build mupdf as a library and import it but no one works well (at least for me). So I suppose (and I hope), I'm doing something wrong during the manipulation.
After I imported the "Android" module from mupdf, the folder is like that :
>android
>manifests
Android.Manifest.xml
>java
>com.artifex.mupdfdemo
All java files
>res
>animator
Xml files
>drawable
Xml files
>layout
Xml files
>values
Xml files
>c
Android.mk
Application.mk
Core.mk
libmupdf.so
mupdf.c
ThirdParty.mk
Even if I try to compile it alone, I have some errors too :
make.exe:***No rule to make target ...
and
Execution failed for task ':android:compileDebugNdk'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 2
Here is the project's build.gradle
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':appcompat_v7')
compile project(':android-support-v4-preferencefragment-master')
compile project(':android-support-v7-gridlayout')
}
android {
compileSdkVersion 19
buildToolsVersion "19.1"
compileOptions.encoding = 'ISO-8859-1'
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
android's build.gradle :
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "19.1.0"
defaultConfig {
//applicationId "com.artifex.mupdfdemo"
minSdkVersion 8
targetSdkVersion 16
ndk {
moduleName "mupdf"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
local.properties
sdk.dir=C\:\\Android\\SDK
ndk.dir=C\:\\android-ndk-r10d
I'm using Android Studio and the SDK is up to date.
I really don't know how to solve that right now, I would be glad If you have any advice that can help me. If you need any other details or files to add, just ask.
Thank you.
My solution is:
I'm having the .so files in lib/armeabi and lib/armeabi-v7a, and in the build.gradle I added jniLibs.srcDirs = ['libs'] to the existing sourcesets. Hope that is helping you!