NoClassDefFoundError with Mapsforge 0.4.0 and Eclipse - android

I am trying to add a map view to my application using Mapsforge. I have done the following:
Downloaded jar files and placed them in the libs/ folder
mapsforge-core-0.4.0.jar
mapsforge-map-0.4.0.jar
mapsforge-map-android-0.4.0.jar
mapsforge-map-reader-0.4.0.jar
Right-clicked file and selected Build Path > Add to Build Path.
In Project Properties, marked the four jars as exported.
However, when I run my app, it crashes on the first call to a class from the library:
E/AndroidRuntime(21265): java.lang.NoClassDefFoundError: org.mapsforge.map.android.graphics.AndroidGraphicFactory
Android SDK tools are all above version 17. No Maven involved.
I've been searching for an answer, but to no avail. I've tried moving the jars up in the list, cleaning the project – this and the things I did already are the essence of what's being suggested on the net. Nothing helped.
When I examine the contents of bin/dexedLibs, I notice that jars for mapsforge were created but are virtually empty, except for the manifest file and (in the case of the maps jar) the osmarender resources. Notably, the classes.dex file is absent. The Android support library in that folder contains a classes.dex file.
Any clues?
EDIT: I examined the original jar files. When looking at the .class files, I noticed each of them starts with CA FE BA BE 00 00 00 33, i.e. is in Java 7 format.
According to some of the information I found on the net, Java 7 is not supported by Android SDK. Is that still the case? This would explain why nothing works but would make me wonder why the Mapsforge devs would use Java 7 to compile a jar that is to be used with Android...

NoClassDefFound is really a hard Exception to solve,a workaround you can try.
workaroud: Java Build Path -> Oeder and Export -> make sur 3rd.jar above yourPath/src
I know android support java7, only when you use the version above 19.

#Ninja pointed me in the right direction but I'll post the detailed steps here.
Short answer: You need version 19 or higher of the Android toolchain, as that version introduced the Java 7 support needed to build against the prebuilt Mapsforge 0.4.0 libraries.
How to update:
Start ADT. Update all installed packages and additionally select at least one version of Android SDK Build-tools that is 19 or higher. (You can have multiple versions of the Android SDK Build-tools installed alongside each other.)
Now open Eclipse and select Help > Check for Updates from the menu.
If you get an error message that no software sources are available, go to Help > Install new software. In the dialog, click Add and add a new repository named ADT Plugin, URL https://dl-ssl.google.com/android/eclipse/. Then retry.
Restart Eclipse when prompted to do so.
Setting the compiler compliance level turned out not to be necessary in my case (I left it at 1.6).
With these steps my Mapsforge project works – I can display a map and the NoClassDefFoundError is gone.

Related

Google-Play-Services Lib Project - Gone Today After SDK Update [duplicate]

I updated the Google Play Services version from the revision 29 to 30 using the Android SDK Manager, but after updating the directory "<sdk>/extras/google/google_play_services/libproject" disappeared, leaving only the directories "docs" and " samples".
I've tried uninstall and reinstall several times but always happens to miss the directory "libproject".
Anyone had this problem with the update?
I'm using Debian Linux 8.4 (jessie) although not believe it has anything to do with the problem.
Looks like Google just broke down Google Play Services into multiple libraries. You'll find them in <sdk>/extras/google/m2repository/com/google/android/gms, if you also updated Google Repository through the SDK Manager.
The individual libraries are in aar format, so you'll have to extract the jar yourself, if that's what you're after.
I am working on a legacy project in Eclipse and I fixed the problem a slightly different way than the others. For me using the project from Google Play Services revision 29, had all sorts of dependency problems which I could not resolve. For example it wanted the compatibility library v4 so I imported it but even then it could not find some required resources.
However, I was able to use Revision 28 without such issues and set the minimum version of my app to be ICS. Below is a link to version 28. Download it, unzip it and extract the libproject folder to where it would normally have been prior to removal.
Import the project in Eclipse (ensure copy files is selected) the usual way and all will be fine.
https://dl-ssl.google.com/android/repository/google_play_services_8298000_r28.zip
For now I downgraded back to revision 29 (and worked well) using the version history available on this site: http://www.smorgasbork.com/2015/01/05/google-play-services-sdk-version-history
I believe it is possible that this is the new format that Google will provide the libs (in .aar files) up because of the description of the update:
The revision number 29 says "client library and sample code" and the revision number 30 says "javadocs and and sample code".
The m2repository folder contains aar files used for android studio. If you look at the samples folder and open some of the sample apps project.properties file you will see that the sample apps still reference the google-play-services_lib. This is for sure to be fixed by google, I saw also people complaining about display ads problem, so maybe they will come back with an update quite soon.
I posted a question about this in the Google Mobile Ads SDK Developers forum. Summarizing the steps in the answer (from Veer Busani, Mobile Ads SDK Team):
We would never recommend you to rename/edit any part of the Android SDK. If you find any issues, do let us know and we would look into it. As to your Mobile Ads/Unity/Android integration, I will certainly help you. Please follow these steps if you are on Google Play Service revision 30.0 (v 9.0) -
Make a new project and import the Mobile Ads Unity package.
Copy our demo script, make a new empty GameObject and add the script as the component.
Right click on Assets > PlayServicesResolver folder and select Google Play Services > Resolve Client Jars.
There is a known issue with GMS revision 30 in Unity. To build for Android, you would need to select Assets > Plugins > Android > firebase-common-9.0.0.aar file and in the Unity Inspector, deselect Android under the Platform for Plugins sections.
Finally, edit the Bundle Identifier in your Player Settings and deploy your awesome project to your Android device.
This worked.

Replacing android.jar provided with Terminal-IDE for newer SDK levels?

Background: I have been using the Terminal-IDE program to learn about doing Android development (I like vim, for starters...).
https://play.google.com/store/apps/details?id=com.spartacusrex.spartacuside
As shipped, it supports SDK level 9. I want to support level 14 (Android 4.0+), so that I can use GridLayout instead of the more complex TableLayout.
I emailed the author, who responded in less than a day (kudos!), but, when I look for a replacement android.jar under /system on my tablet (Nexus 7 model 2), that particular jar does not exist, only many other jars with longer names that are just wrappers around dex files.
Anybody ran into this problem and solved it?
Upon further emails with the author of the environment, I found an easy solution:
Go to the system/classes directory of the T-IDE install
Rename the existing jar (e.g. - android.jar.t-ide)
Copy the android.jar from the SDK (or sdk directory within Android Studio) with an alternate name (e.g. - android.jar.studio.sdk)
Make a symbolic link from the updated SDK jar to android.jar
Now I can use GridLayout from Android 4.0 - compiles (on the tablet) and runs just fine. I did not need to update any other environment variables or configurations, as I replaced the original android.jar with a sym-link to the updated jar (and an "ls -l" will show which one is being used as "android.jar").
Note: if you get the updated android.jar from Android Studio, be sure to get the one in the sdk directory, not the one in the "plugins" directory, which won't work.

Unable to find package com.google.cast

I recently updated ADT to point to Google APIs 18. The install went fine it seems and I'm able to point my Project Properties to Google APIs 18, however, Eclipse can't find the package com.google.cast. Anyone else having this problem?
That's because com.google.cast is not part of Android.
Near as I can tell, you will need to download a ZIP file containing their library project, import it into your IDE, mark it as actually being a library project, then attach that library project to your app.
Actually using those APIs appears to require a whitelisting, and it is in violation of their license to actually distribute an app (or, near as I can tell, source code) without express written permission of Google.
CommonsWare is correct, additionally, you'll need the v18 Android Support Libraries. v7/mediaRouter & v7/appCompat
I finally got this to work for me. Originally, I tried doing it like I used ActionBarSherlock (making it a library, went to Project -> Properties and told it to use that library, etc) but that didn't work. Finally, I got frustrated and simply moved the GoogleCastSdkAndroid-1.0.0.jar file from the lib folder of the library directly into the lib folder of the project.
So, again, I imported from existing code the SDK into my workspace, then took the jar file from its library and put it directly into my project's lib folder. Not sure if that's how it's supposed to be, but the sample TicTacToe game is now error free and runs on my Nexus 4.
It sounds like you're trying to run one of the Google Cast sample apps without having installed the Google Cast SDK. The instructions for installing the SDK and all necessary support libraries were just uploaded here on GitHub. I'm quoting below the relevant section for installing the Cast SDK itself:
http://developer.android.com/tools/support-library/setup.html#libs-with-res
You can either add the Cast SDK as a library project in your workspace, or add
the GoogleCastSdkAndroid-x.x.x.jar directly to the project you're building. The
former is recommended if you have multiple Cast-related projects in your
workspace.
As a library project: Follow the Support Library setup instructions linked
above for your downloaded and extracted SDK.
As an included library:
Copy the /libs folder from your downloaded SDK to your Cast-related project.
In the Package Explorer window, open (your Cast project)/libs and right
click on GoogleCastSdkAndroid-x.x.x.jar. Select Build Path->Add to Build
Path.

Android Library project organization

I have an Android Apps (A) project that depends on a Library project (B). The library project contains code as well as third-party jar files and some other jars that were exported from projects C and D. In Eclipse, I have project B specified as a library project.
However, when I connect my device and run project A (Run As -> Android Application), it crashes on the device and when I examine the LogCat output, there is a NoClassDefFoundError exception for one of the classes that exists in the jar files of project C.
When I unpack the B.jar file in Project B's bin folder, it does not contain anything else besides the META-INF/ folder with an empty MANIFEST.MF file. So this indicates that something seems to be going wrong someplace, but I'm unable to figure it out.
Could anybody help me with this issue?
Are you working with the latest ADT plugin and SDK revision? That is rev 22.x. If so there has been an important change to the dependency management.
Possible solution
For some reason the contents of the Order and Export tab has completely changed and you now have to export the Android Private Libraries from your library projects. See screenshot below:
More details
The tricky part of this change is that your project still compiles properly in Eclipse so you're not aware of any issues. Until you deploy the app on an emulator or device and you get the ClassDefNotFoundException on any call of a library project.
Not confirmed but I believe this is related to recent changes for maven support, also related to android studio preview
Similar change in the past
This reminds me of a similar change in the update to rev 17 where the lib folder suddenly changed to libs and all content from the original lib folder wasn't packaged so you wouldn't see any issues in eclipse. Only once installed on a device.
More information that 'issue' is available on this link. If you search on stackoverflow for "sdk 17" and "classdefnotfound' you'll also get enoug questions about that change.

Library Projects support?

I have been trying to work with a Library Project, just like it's mentioned in the documentation :
http://developer.android.com/guide/developing/eclipse-adt.html
I have created my Library Project as a Android 1.6 Project and now I have been trying to reference to it out of my second project (also an Android 1.6 project) and I am getting the following error :
"Target 'Android 1.6' does not support building project with libraries."
"ERROR: Unknown option '--auto-add-overlay'"
The documentation states that supported platfroms are the 1.5 onwards (with exception for the 2.0 & 2.0.1) and that the second project should have the same platform or higher (in my case the same)...
So any idea what's ahppening here ? And most importantly : any idea how to solve this ?
Thx in advance !
How is the library project compiled as? is it a jar file? And in eclipse, did you add it in Eclipse as "Project Name" -> Right click -> Configure build path -> Libraries. Click on Add External jars and add your jar file.
First of all to reiterate what was said in the previous comment..
A "Library Project" in Android terms is not just a dependent project or an external jar. It is an Android concept introduced by the Android team see below...
http://developer.android.com/guide/developing/eclipse-adt.html
Tiger, have you found a workaround to this yet?
I'm having exactly the same issue and after battling with this for a while now I'm pretty sure it's a bug (but this particular bug is quite old and might just look very similar) Have a look at:
http://code.google.com/p/android/issues/detail?id=8498
Yes, it appears that certain SDK levels in Linux aren't supporting the "--auto-add-overlay" option required when using libraries in Eclipse. I've found that 1.6 works find, as does 2.1-update1, but 2.0 fails. I ended up changing my app to rely on 2.1 instead of 2.0 and it worked.

Categories

Resources