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!
Related
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.
I have a dummy project, which I succeed to compile through buildship plugin in eclipse IDE.
This is my local.properties file:
sdk.dir=C:/Asta/altro/adt-bundle/sdk
This is settings.gradle file
rootProject.name = 'testgradle'
This is my build.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.testgradle"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.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']
}
}
lintOptions {
abortOnError false
}
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
}
Despite I got the apk fully compiled, eclipse is not integrated: still seeing missing libraries and giving more than a 100 errors! All the libs are perfectly managed by gradle in \build\intermediates\ and assembled into apk, but the eclipse IDE is not "live". I would like to use gradle to download and explode the libraries and then to inform eclipse and let it to make the apk with its own builder.
Buildship can be used only to run Android tasks (assembleDebug).
During the build process it will load dependencies and tell if there're some errors.
To load dependencies into Java classpath, to see errors in Eclipse and resolve imports you can either manually add .jar files to your Java Build Path or use this Gradle plugin: https://github.com/greensopinion/gradle-android-eclipse.
It generates classpath for Eclipse project and you just import it into the IDE.
To run Gradle tasks you can create a Run configuration (named "Gradle Project") and put there your task and Working directory.
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
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 am working on a project in eclipse, but after sometime it giving me error like "Unable to execute dex: method ID not in" as single DEX file having 65k method limitations.
To overcome the issue I come into the picture of Gradle plugin v0.14.0 for Android adds support for Multi-Dex. So I moved to Android Studio.
I have updated SDK and exported project from eclipse as per Migrating from Eclipse.
Now I have project structure required in Android Studio.Their is dependency of project on ABS, Google Play Service lib and android multidex support lib. I have added these libraries to my project folder named "libraries".
Project Gradle file looks something below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':libraries:ABS')
compile project(':libraries:GooglePlayServiceLib')
compile (project(':libraries:android-support-multidex')) {
exclude group: 'com.android.support', module: 'support-v4'
}
compile "com.android.support:support-v4:21.0.0"
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
dexOptions {
preDexLibraries = false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
When I clean and build project it builds successfully. But when I run project as android application giving me following error:
java.lang.RuntimeException: Unable to instantiate application java.lang.ClassNotFoundException: Didn't find class on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example-2, /vendor/lib, /system/lib]]
I am thinking that application is not compiling AndroidManifest.xml OR I am something missing ?
Any help is going to be appreciated. :)