Graphhopper not working in release apk. - java

I have developed an android application using the graphhopper routing library. The library works fine in debug mode or in app-debug.apk but when I create a release apk of the app the library wont work. It is giving me java.lang.IllegalStateException: No input stream found in class path!? exception upon execution of the following code.
/*
*Constants.ROUTE_FILE_PATH = Environment.getExternalStorageDirectory().getPath()+"/.myappfolder/routes";
*/
File routingFiles = new File(Constants.ROUTE_FILE_PATH);
GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.load(routingFiles.getAbsolutePath());
While creating the release apk i got some warning for the graphhopper library and removed the warnings using
-dontwarn com.graphhopper.**
in the proguard-rules.pro file.
Is there any issue with creating a release apk of the graphhopper project?
Why wont the library work in release version of the apk?

Ok so I have found 2 answers to the issue.
Firstly, you can set
minifyEnabled false
in build.gradle. This works as a solution too but your app wont get minified.
Secondly according to the answer posted here you can set
-keep class com.graphhopper.** { *; }
in the proguard-rules.pro.
So whichever answer suits you best.

Related

The plugin `firebase_auth` doesn't have a main class defined in C:\Users\

When adding firebase_auth to dependencies (pubspec.yaml) to my flutter project I'm getting this error:
The plugin firebase_auth doesn't have a main class defined in C:\Users(username)\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_auth-3.1.3\android\src\main\java\io\flutter\plugins\firebase\auth\FlutterFirebaseAuthPlugin.java or C:\Users(username)\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_auth-3.1.3\android\src\main\kotlin\io\flutter\plugins\firebase\auth\FlutterFirebaseAuthPlugin.kt. This is likely to due to an incorrect androidPackage: io.flutter.plugins.firebase.auth or mainClass entry in the plugin's pubspec.yaml.
If you are the author of this plugin, fix the androidPackage entry or move the main class to any of locations used above. Otherwise, please contact the author of this plugin and consider using a different plugin in the meanwhile.
My code is just the dummy code created by android studio and the only thing i added is firebase_auth: ^3.1.3 in pubsbec.yaml , the .json file in the android/app directory and registered the app on Firebase website.
I get the same issue in VS Code, so Android Studio is not the problem.
I would really appreciate any help!
Add the firebase_core pugin because it is essential and if you did everything according to the documentation then flutter clean after that pub cache repair will do the the work. then again run.
I think you haven't added Firebase core in your pubspec.yaml file. Try to add firebase_core 1.7.0 in your pubspec.yaml and then clean your project using this command flutter clean
also Checkout this installation guide

How to access aar file, in libs, from Main

I spent the last three days trying to read an .aar in Android Studio and I just can't figure it out.
My project view looks like this:
--- AnApplication
----------------------.gradle
-----------------------.idea
----------------------- app
-------------------------------- build
-------------------------------- libs
---------------------------------------- cube5-debug.aar
(...)
I want to access a class inside cube5-debug.aar from my main activity.
I know the class is there in the .aar file.
I don't know the precise import line I must write at the start of my main.
I have tried import com.company_cube.cube5 (the package of the project where I generated my .aar) and many other variants.
I don't know if Android Studio is recognizing the file as a library. However, the files sync with the gradle successfully.
(For context, the project where I generated the .aar was made by Unity, by exporting a Unity project into an Android one, and then generating the .aar from that one; the goal was to use this .aar file as a library in a second Android Studio project - the one I am talking about in this post)
I am patiently waiting for any help you can give me. Thanks
EDIT: To import the .aar, I followed the images of this small post:
Importing .aar in android Studio
And solved the error the post reports by putting the .aar in the libs folder like Daniel Nugent said. However, when I try to write, in the Main:
Intent intent = new Intent(getApplicationContext(),UnityPlayerActivity.class);
AS doesn't recognize UnitPlayerActivity. This class is inside the .aar file supposedly. Before making the aar in my first AS project, it was here:
cube5->libs->unity-classes.jar->com.unity3d.player->UnityPlayerActivity
When I open the .aar with Winrar, and open unity-classes.jar with a text editor, I see a almost everything as encoded symbols.
I'm not sure it is normal. Any idea?
EDIT 2: I think I know where the error is: when I import my .aar, I get an IDE fatal error. I don't know how to solve it, so if you can, please check the post I made about it:
IDE fatal error on importing .aar
For android Studio 2.3.3 you can use
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'cube5-debug', ext: 'aar')
}
in the app level build.gradle. I did't check it for AS 3.0.
Add .aar file to your app by doing:
in project build.gradle
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
in app build.gradle
dependencies {
compile(name:'cube5-debug', ext:'aar')
}
So I managed to solve it. The .aar file I talked about was exported with AS, after I imported an Unity project into AS. I did this in order to use the Unity program inside AS. However, this gives error for some versions of Unity and AS. I installed Unity 5.5.0f3 and an older version of AS, and everything worked fine.
Note1: if you aim to install that Unity version, you will be prompted with a requirement of some windows 10 tool, which you must get (I cannot remember the name). I did it by downloading windows 10 install and installing only that tool, which comes with the package.
Note2: I made the program from Unity work inside AS but only because it was a simple program. I later wanted to do an Augmented Reality App in Unity, and use it in AS, but it cannot be done apparently. Evertyting works fine until I import the .aar into AS, and a class in that .aar library gets unresolved ("Video player”). This should have to do with the AR camera class, which AS does not recognize. I ended up creating a AR app with Unity, another app in AS, and from the AS app, calling the Unity app with two lines of code, whenever necessary. To return to the AS app, now in background, I simple click the back button, which is recognized by the Unity app (if you make code in Unity for it) and makes it destroy itself, returning to the AS app.

Crashlytics Android: app could not be located

To create an application and has built fabric.io.
My app release 1.1 - everything works, statistics comes.
My app released 1.2 - it does not work, the statistics do not come.
When you come on the dashboard fabric.io:
Alert! Sorry, the app could not be located.
An important point:
If you build debug version - it works!
If the release version of the GoogleStore - is not working! (Although version 1.1 of the GoogleStore - works!)
Checked logcat release version:
Logcat: I/Fabric: Initializing Crashlytics 2.2.2.37
What could be wrong? How to solve this problem?
Thank you!
If you are building a release version and using ProGuard you should add following lines in your ProGuard file:
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
This documentation could be useful for you too Dex and ProGuard and Advanced Setup.

Android Studio - Gradle 1.5 --core-library option

I have a problem with my Android project and Gradle 1.5.
I am not able to compile my dependencies I added. Currently I am developing an Java EE application and I want to perform an EJB lookup from my Android device to my running Wildfly10.
I know, doing a lookup from an android device might not be the best option, a REST webservice would be better, but thats not the point here.
In my project I added a new module, containing all my external libs, and I added this module to my :app as dependency on "compile" level. Everything just works fine, until I want to add the jboss-client.jar. During dex, he is complaining about the javax.transaction.*.
What I have done for now
added multiDexEnabled true
added preDexLibraries false
playing around with all other dex options
also I tried this: Android dx tool
this: Android Studio ignore --core-library flag
and set the --core-library flag in Android Studio settings
Why they are not working
solution: I modified my dx.bat in every build-tool I have .. nothing changed. It's just not working
solution: com.android.build.gradle.tasks.Dex is not known (and I have no idea how to add), coreLibrary is not supported with Gradle 1.5
solution: is completely ignored by gradle
The projects minSDK is 19 and targetSDK is 23 with build-tool 23.0.2
I called the dx.bat from command-line with the same parameters as gradle, I only added the --core-library arg and it works! But that doesnt solve the problem within Android Studio and Gradle.
Can anyone please help me?
UPDATE:
Okay, I had a look at the source code of com.android.dx.command.Main. There is a public inner class "Arguments" which contains (apperently) the arguments which can be used, also the coreLibrary=false. Now I only need to know how to modify it. Does anybody know?
Best regards,
Chris
This worked for me:
dexOptions {
preDexLibraries = false
additionalParameters =["--core-library"]
}

Using jackson-dataformat-xml on android

I'm strugling with using jackson-dataformat-xml on android
I have some very basic code that works fine on oracle jre
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
First I tried official documentation adapted for gradle (by me, not sure if done correctly):
compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'javax.xml.stream:stax-api:1.0-2'
Result: gradle fails build time about bundling corelibraries into an application
...
:app:preDexDebug
trouble processing "javax/xml/stream/EventFilter.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
...
2nd attempt trying to follow Sean's answer
(Basicly he repackages corelibs with prefix names and rebuilds jackson-dataformat-xml to use the prefixed names)
compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'
// Repackaged XML-specific libraries
compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'
compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'
compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'
compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'
And build time failed on duplicates
Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec
so added:
packagingOptions {
...
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
When adding the exclusions it builds and deploys, but fails runtime on below stackdump (AFAIK it cant find the SAX provider, even tho it is added to the classpath to my understanding)
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:97)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:82)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:46)
What is the proper way to move forward on either #1 or #2?
Number 2 is the correct approach (Android doesn't like it when you include classes in the official Java package namespace - but then again, I wrote the original answer so I'm biased ;) ).
I believe the FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found error is due to a bug in the Android build tools. In previous versions of ADT for Eclipse and Gradle plugin < 0.7.0 the /META-INF/* files are stripped from the JARs during the build process. It seems like >= v0.7.0 shouldn't have the problem according to Google, but from others' reports it sounds like it still may be problematic, and could potentially remove the META-INF/services/javax.xml.stream.XMLInputFactory file, which is required for the platform to register Aalto.
Try the workaround mentioned in AOSP issue 59658 comment 22:
right click on /src/main (where you have /java and /res folders),
select New > Folder > Java Resources Folder,
click Finish (do not change Folder Location),
right click on new /resources folder,
select New > Directory
enter "META-INF" (without quotes),
right click on /resources/META-INF folder,
select New > Directory
enter "services" (without quotes)
copy any file you need into /resources/META-INF/services
For you, in step 10 above you'd need to copy this file into /resources/META-INF/services. In case the file link is broken in the future, the name of the file is javax.xml.stream.XMLInputFactory and it consists of a single line:
com.fasterxml.aalto.stax.InputFactoryImpl
EDIT
If you get a "Error:duplicate files during packaging of APK... Path in archive: META-INF/services/javax.xml.stream.XMLInputFactory", you can try telling Gradle to keep the first occurrence with:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.xml.stream.XMLInputFactory'
}
}
EDIT 2
This bug may be affecting "pickFirst". Please make sure you're running the latest version of Android Studio, and update your local tools and Android Gradle plugin to make sure you're running the most recent version of the tools. This may be fixed in Android Studio 1.3 RC1.
I have attempted to add XmlPull support to jackson xml. Find the forked project here:
https://github.com/finvu/jackson-dataformat-xml
Currently, only supported for version 2.9.6. (clone the branch jackson-dataformat-xml-2.9.6-XmlPull)
Sorry, I am not able to provide detailed documentation due to time constraints. If you have knowledge of git and maven to pull a specific branch and build the jar, then it should be relatively easy.
To those who will be in need of this in the future:
first integrate Jitpack in Your Android app, following their instructions:
https://jitpack.io/
Then paste teh GitHub url of jackson-dataformat-xml on Jitpack sites' corresponding text box. GitHub url is:
https://github.com/FasterXML/jackson-dataformat-xml.
That's it! Enjoy the result. :)

Categories

Resources