Android Library project organization - android

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.

Related

How to make debugging work in Android Library projects?

I have an android project consisting of multiple subprojects and one of those subprojects is network, the problem is debugging breakpoints doesn't work in the network library project and also Android.Util.Log doesn't work too, so i don't have any way to debug the project right now and that's really makes things tough while fixing some issues or adding new functionality in the project. On a breakpoint it says
no executable code at line 42
also when i load the project (the one containing all the other projects in android studio) it says can't load 3 modules fine, but they work when i run them.
Just wanted to know if anyone else is facing the problem and what could be the solution.
I have tried putting the .iml files in .idea/modules/network and it helps me get rid of the error of can't load modules. I've tried cleaning the project already and rebuilding it. Restarting android studio, upgrading android studio I am on the latest version of android studio now.
When i open the project in intellij idea ultimate it gives me message that unsupported projects, can't have java projects with gradle projects in android. But the projects i have are Andriod library projects with their own build.gradle files.
It sounds to me like what's happening is your application is being built with older compiled versions of the libraries. How are they included in the project, gradle dependencies?
To get logging in you would need to open the modules add the logging and re-build them.
Copying around .iml is not a good idea in general. The correct process is to do an import in Android Studio. Here is a pretty good tutorial http://www.truiton.com/2015/02/android-studio-add-library-project/
The last step about adding it to your gradle file to compile is important that is was will allow it to pick up changes, like adding logging.

Lots of compile errors after Android Launcher Source Code is imported into workspace

I have task to modify default android gingerbread launcher (android 2.3). I want to download launcher's sources and add functionality according to my task. I have found sources here:
android Gingerbread launcher sources
I download this and import into workspace as is. As a result I get numerous compile errors (some classes are missing, instance variables are missing, etc). Why? I mean why wouldn't it compile? What should I do to make it compile?
P.S. By the way, when project is imported, used platform as per project settings is not 2.3, so I have to manually set it to 2.3. However, numerous errors still remain.

Install app on genymotion device ,meet:“INSTALL_FAILED_CPU_ABI_INCOMPATIBLE”

When I install my app on a genymotion simulater device,it can not be installed well,on console I got "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE"
I trid another app,it installed fine.I do not know why.
The application (certainly a game) must be ARM only.
Genymotion is a x86 platform, so compile the application to target x86.
You may be able to install ARM support manually :
http://forum.xda-developers.com/showthread.php?t=2528952
If you are using IntelliJ it may be related to the project's default configuration. IntelliJ will assume, unless otherwise specified, that Native libraries will be stored in the Libs folder. This is usually where developer store their JAR libraries. IntelliJ build process will package up the JAR file into the Native file folder in the APK.
If you experiencing this problem, you can find a good How-to:
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE Intellj
This helped to resolve the issue I had.
You might want to check out my answer here:
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE on device using intellij
I know it's written for IntelliJ, but you could be running into a similar issue with Eclipse where it thinks that some normal Java files or jar libraries are native code and including it in the compiled APK. A quick way to find out is to open up the final APK (it's just a jar file, so most utilities should be able to decompress it) and make sure that the only things you see are META-INF, res, AndroidManifest.xml, classes.dex, and resources.arsc. It's possible that there are other valid files in a normal Java Android application, but in general if you see anything else in there, particularly a libs folder, it's probably the result of the compilation process thinking that those other things are native libraries (compiled C/C++ code using the JNI).
If this is the case, you'll need to configure Eclipse to not interpret the Java libraries you're using as native code. Now, I don't personally use Eclipse so I don't know where the proper settings would be, but based off of this answer, it looks like Eclipse automatically assumes that the libs folder in the root of your project contains native libraries. The easiest solution may be to move any Java libraries you are using into a different folder (such as libraries).
http://blog.iteedee.com/2014/02/android-install_failed_cpu_abi_incompatible-intellj/
The INSTALL_FAILED_CPU_ABI_INCOMPATIBLE error is generated when you attempt to install an android application on a device with an unsupported CPU architecture. This error is usually related to the native libraries that are not packaged up for the device’s CPU architecture (ie: x86, ARMv6, ARMv7, etc).
Now, if you have an application that doesn’t use any native libraries or *.so file you might be scratching your head on this one. If you use IntelliJ IDEA IDE for your android development it might be packaging all of your related .JAR file in to the Native Library file location in your APK.
The cause of the same problem was different in my case.
I had added some dependency jars in /libs directory of my Android app project. One of these jars had exported library in jar format; i.e. a jar within a jar file. I've noticed that the apk created using jars with such structure are incompatible with x86 based devices (don't know why).

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 Test Project Directory Structure When Using Eclipse

Once upon a time, I avoided Eclipse for Android development. And life was good.
Along the way, I adopted a convention originally supported by the Android command-line build tools, of having a tests/ subdirectory containing the test code (e.g., MyProject/ being the home of the app, MyProject/tests/ being the home of the test suite). Android does an excellent job of allowing test code to reside in a separate-but-related project, and having it as a subdirectory kept the tests logically co-located with the project proper.
I am now switching to Eclipse, as I need to support it better for my subscribers. The only way for me to do a quality job of supporting it is to use it daily. And, since I have a quad-core with 4GB of RAM, Eclipse actually starts up in less than a minute. :-)
However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).
So, my questions are:
Am I correct in this assessment, and if I'm wrong, are there any particular steps I should take to ensure that Eclipse is happy? I find that Eclipse can sometimes get a wee bit cranky...
How are Android developers organizing test projects relative to the project being tested? Peer directories (e.g., MyProject/ for the app, MyProjectTests/ for the tests)? Peer subdirectories under some targeted common top (e.g., MyProject/app/ for the Android app, MyProject/tests/ for the test suite?)? Something else?
BTW, I'm running Eclipse 3.5.2, if that matters.
Thanks!
I've been creating test projects with Eclipse 3.6.2 inside my main project just like you describe for command line tools (MyProject and MyProject/test are Android projects that both contain a src folder). You can create this test project using the New Android Test Project by deselecting "Default Location" and setting the path.
None of my projects are very large, but the only problem I've had so far is that you cannot use the MyProject/test folder under the MyProject project. To be able to right click and run as a test case, you have to access files directly from the MyProjectTest project. To prevent you from having problems, you can add a Resource Filter to hide the test folder in Project Properties > Resource > Resource Filters.
However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).
What problems have you seen?
Depends on your toolset:
ADT >= v12 currently has flaky support for "a project within a project":
Creating an Android Test project in Eclipse
I have tried separate testproject, and separate test directory, but afaik "a project within a project" approach seems to be the way of the future.
This is becuase AndroidManifest.xml merging into the test project AndroidManifest.xml, is in the pipeline for the next ADT releases.

Categories

Resources