Android apk builds fine, but shows ClassDefNotFound error when running - android

I am using Netbeans 7.1.1 and nbandroid plugin updated to latest this morning. When I made a build, everything built fine. I installed the apk on a device that is running Android 2.3.3. I am using sdk tools r19.
I see java.lang.NoClassDefFoundError in logcat when I try to start it.
My ant build script is copying all the libs the apk depends on to its libs directory and building it. For some reason, some classes are not getting packaged into the apk.
Is it a known issue? Is there a workaround?
I see some workarounds for eclipse along the lines of creating a libs folder (instead of lib folder) under project dir. I have libs property jar.libs.dir configured to point to a folder outside of my project. This all seemed to work before, not now.

Remove the jar.libs.dir property you described.
Move your JAR files into the libs directory.
This should give you the expected results.

Related

Export projects for Android Studio with different Unity versions

INTRODUCTION:
I exported android project from Unity version 4.6.1f1. After that, I imported it in Android Studio. I worked on a project for a few days and everything worked as supposed to.
When I change something in Unity, I just export android project again. In android studio, I delete ASSETS folder and then paste the new one that I get from Unity export. I did this in Eclipse to update my project. I am doing it now and everything works just fine.
PROBLEM PART:
Then, I updated Unity to version 4.6.2p2. I exported android project again. I changed ASSETS folder as usual. I also changed unity-classes.jar. I used this method in Eclipse before and it worked for me (apparently it worked for a lot of people, as my research on the internet confirmed it).
This does not work in Android Studio. I get error
Invalid serialized file version. Expected version: 4.6.2p2. Actual version: 4.6.1f1.
I tried: restarting Android Studio; cleaning and rebuilding project; syncing gradle; using other versions of Unity,... I also tried removing all dependencies, cleaning project, then adding dependencies again and rebuilding project.
I did not find any reference to this problem on the internet.
The only solution I get so far is to import project in Android Studio as new one and then do all the work again. But that is very undesirable.
Did anyone has this problem and come up with a solution that will not require making new project from scratch?
I did more research and here is the solution.
The problem is that Unity doesn't export all libraries together now. Specifically, libmain.so libmono.so and libunity.so are now separated and you need to change them also after you export project with new version of Unity (changing unity-classes.jar and assets folder is mandatory as before).
When you export project from Unity, you can find those libraries in libs/armeabi-v7a folder. In Android Studio, you can find them in src/main/jniLibs/armeabi-v7a folder.

Android project with library builds fine with Eclipse but not with "ant release"

I have a project which uses another library project.
When i export a signed apk using eclipse and install it it runs fine.
But, when i build it for release using "ant release", it builds successfully but crashes after installation.
One thing i noticed that the size of apk created via eclipse is larger than the size of apk created via ant. I'm doubting it is not including the library project or some parts of it.
Any idea what might be going wrong here?
My first day with ANT so i dont know much ... any help is appreciated.
=============================================================
Solved myself:
It was happening because an external jar referenced in the library project was not available in the finally released apk. Manually copying it to the libs folder fixed the issue.
ant task will create apk even if there are no classes to compile (e.g. classpath is wrong)
It was happening because an external jar referenced in the library project was not available in the finally released apk. Manually copying it to the libs folder fixed the issue.

Gradle build errors with Android Studio

When I try to build my project in Android Studio I get the following error, using the gradle plugin provided with the download (v 1.6):
The specified Gradle installation is not supported by this tooling API version (1.6, protocol version 4)
When I downgrade to gradle 1.3, 1.4 or 1.5, I get this error:
Gradle: : java.lang.ClassNotFoundException: org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
The project was originally created in Eclipse, the exported using the build gradle file option, then imported into Android Studio.
Does anyone know what I can do to fix these issues? Many thanks.
I had a similar problem and I believe that it was caused by having multiple versions of gradle on my machine. The solution I found was to use the script that Android Studio creates in your project folder (either gradlew (MacOs/Unix) or gradlew.bat (Windows)):
./gradlew assemble
This causes the correct version of gradle to be run - i.e. the version that was shipped with Android Studio.
I haven't tried creating a project within Eclipse, so I'm not sure if these scripts are created when creating your project in that way.
I think the problem is with the way Eclipse 22 exports the project. In the end the way I got my project transferred over was to create a new project in Android Studio and copy over the files from my Eclipse project into the appropriate directories in the new project.
The directory structure of projects in Android Studio is very different to the structure in Eclipse, and there are several files created when you start a new project which you don't get when importing a project from Eclipse (e.g. gradlew.bat, settings.gradle).
I also had this problem which can indeed be worked around with Mark's suggestion of using ./gradlew assemble.
However, this does not help you run Make Project from within Android Studio.
To do that, I had to go to Preferences / Gradle / Use local gradle distribution
and select any random (but NOT gradle) folder inside the project folder.
You might notice that this is marked as an invalid location, but you can ignore that, it seems...
Not a great solution, but it works.

Android ActionBarSherlock on NetBeans - working but editor showing errors

I'm using NetBeans for android application. I installed properly (I think) ActionBarSherlock package as android library project. Everything works fine, I can build and run application, but code editor doesn't recognize ABS classes (just look at screenshot, BUILD SUCCESSFUL but errors exists) and code completion doesn't work too.
My configuration:
Stable NetBeans 7.2 with android plugin ver. 1.13
Linux Mint 13 Maya 64 bit, Mate
ActionBarSherlock ver 4.2 (stable)
How I installed ABS:
Download and extract source
From sdk/tools run command:
./android update project -p path_to_ActionBarSherlock/library/
Similar command to connect android project library with my test project (there is similar option in Netbeans IDE but I get error that this is not android library project)
./android update project -l path_to_ActionBarSherlock/library/ -p path_to_my_test_project
I have tried clean and build on both projects but no results. Any idea?
Regards
The way I finally managed to add ActionBarSherlock to my android project on Netbeans was to:
Download the latest version of ActionBarSherlock and unzip it
Go to the subfolder called library and remove the pom.xml file from there (with one of the previous versions it didn't work. I had to first build it, close it and remove not only pom.xml but also some netbeans properties files)
Open that subproject (library) in the Netbeans
Now this project will no longer be seen as a maven project. Netbeans will see it as an Android project. Then I:
Clean&build it
Add it to my-project's library properties (right-click on my-project, properties, library, add, point the proper location of library project). Important here was to copy/move that library project somewhere near my-project. Otherwise it claimed that it cannot open it.
And from now on it works fine.
Key to that thinking was that Netbeans didn't want to add the provided library project cause it saw it as a Maven project. When the pom is deleted, Netbeans no longer sees it as Maven project nut as an Android project and it can without any objections add it as an Android's project library.
Probably there are better solutions, but I didn't find any and that was the only one working for me.
Hope it helps.
You can also make a new Android project, and then copy and paste the needed files in the new project.
So only copy:
libs, res, src, AndroidManifest.xml

Significance of com.android.ide.eclipse.adt.LIBRARIES in build path?

I've update to the latest SDK(4.0.x), tools(r16) and plugin(16.0.1) for Eclipse. I notice that now nearly all my projects in Eclipse have the library mentioned in this question's title showing as a referenced library in the Libraries tab of the Java build path. This is relatively new, though I'm not sure in which upgrade of the SDK it appeared.
It's not causing any problems but I'd quite like to know what its purpose is?
Interestingly it does not appear in projects which I also build using Ant from the command line. In these projects I send the Ant built binaries to a folder outside the Eclipse workspace. These projects naturally have a build.xml, an ant.properties and a proguard.cfg in the project root. This I suspect has something to do with why the com.android... library isn't in the build path. These projects build perfectly OK when built under Eclipse.
None of my projects are library projects.
Update: If I delete it from the Java build path, it appears to have no ill effects, in so far as the app still builds (even under Eclipse) and runs OK.
If you have any "Android Libraries" set in the Android section of the project then these are for linking in those libraries (the jars that the plugin will build)

Categories

Resources