I am developing first time Android Library Project that have external dependences of different libraries like retrofit and ormlite-android. The problem i am facing right now is when i use my Android Library Project .aar file inside other project the class not found exception occur when run the code. Please can any one guide me how to fix such issues. Do i have to add external libraries reference inside my dependent app ?
Related
I have problems with accessing resources in my android library. I have created library project with some resources (com.library) and then I imported module into application project (com.app). So I have Android Studio project with library and application.
When I want to access some library resource (com.library.R.string.label) I get error during compilation
package com.library.R does not exist
When I want to run some library method from application which contains/uses R.string.label I get
java.lang.NoClassDefFoundError: com.library.R$string
I added library to application gradle file using
compile project(':Library')
and from IDE perspective looks everything fine and R.java is created with references to resources. I want same usage as I'm using for example android.R.string.cancel or similar libraries in my application project.Where I'm doing mistake? Thank you for help.
PS: In the future I want to have my library project as aar package.
As soon as you add a library to your project all resources will be "copied" to the R-file of your app. So if you want to access a string from your library you don't do something like getString(com.library.R.string.some_string) you simply call getString(R.string.some_string) instead.
In terms of the library method: Would you mind sharing some code with us? Currently I can't imagine what's going wrong.
Problem was in wrong package name in gradle configuration files (after renaming).
I am using:
org.apache.commons.lang.builder.EqualsBuilder
in a in an Android library project (A) that in turn is used in another library project (B).
This works fine in the Android app that consumes library project B.
However, I have built an Android Test project to unit test the Android app - in particular the library project B classes. When doing so I encounter the following exception:
java.lang.NoClassDefFoundError: org.apache.commons.lang.builder.EqualsBuilder
I have included
commons-lang-2.6.jar
which contains the
org.apache.commons.lang.builder.EqualsBuilder
namespace in library project A build path for export.
I have searched SO for this issue and found a number of posts on the NoClassDefFoundError, but none that have a situation with unit testing.
I found the answer. After reviewing this article, I realized that I needed both the jar from project A and the commons-lang-2.6.jar in the test project. Adding BOTH jars to the build path and export resolved the issue.
I am writing an android library project and trying to test it. I found testing a library project
more difficult than it has to be using my current method.
Right now, I am exporting the library project into jar file. Then I put it into the libs folder of the test project and the test target project. Then I add it to build path of both projects and run the test.
Every time I make a change to the library I have to do this again. Is there easier way to do this?
There is some reference to this in the google docs. Check out http://developer.android.com/tools/projects/index.html#testing
Basically, the easiest way is to write an application that uses the library project and then add unittests to that application.
When creating the tests via eclipse, you can choose to test modules from within your library project. This way, changes to the library project are automatically applied.
I've a main project that depends on other Library projects that use external JARS (that are also used in the main project).
Now with ADT17 I have removed from the main project the external libraries that are also used in library projects, because they are automatically inherited from new AD17 Android dependencies (from library projects).
Until here all works correctly. The problem is when I want to create a Test project for the main project. What I do is mark all externals jars and android dependencies as exportable to be inherited in the test project.
But the problem is that Android dependencies although they are market as exportable aren't inherited from the test project and when I run it I get some Link of class X not found... make sure it's in the apk.
I attach an image to make it more clear:
(It's an snapshot from main project libraries. Blue marked ones are correctly inherited and red ones not).
It seems that it was a bug in ADT17 with test projects that depend on external libraries.
Today I've updated to ADT18 and it works correctly without having any lib defined in test project.
I'm trying to use an ActionBar library project in my app but I keep getting errors when trying to add the library reference. I do it as described on the Android Developers website (here) but it only copies the classes across to a folder called "actionbar_src". The error then comes when it tries to find the library's resources within the classes, which it didn't copy across. What am I doing wrong?
Here's a screenshot:
Under 'Java Build Path -> Projects' did you also add the project there? I find I have to do both for the project to compile and run.