Error rendering components from an included library in IntelliJ IDEA 14 - android

I have a layout file that includes controls that are part of a library module that is compiled in the project.
IntelliJ reports that it can't dispaly the control, despite that it shows up properly when running the actual android app on my device.
It suggests rebuilding the project, creating the class, or fixing my build path.
The module that has the controls are in the Dependencies tab, and are set to Export, and Scope=Compile.
The layout file references the custom controls via their fully qualified package/class name.
The rendering API I've selected is the same version as my Target SDK set in my AndroidMainfest.xml
I have tried both using a tag with the class attribute pointing to the class, as well as a tag where the tag name is the fully qualified class. Both result in IntelliJ not being able to render the view.

I was able to solve this by specifying a Project compiler output directory at the IntelliJ project level. Prior to this fix, my library modules used an output path as a subdirectory of where the module is defined.
File > Project Structure > Project compiler output.
Set it to the standard "\out"
Next, I set my library modules up to use the inherited project output path.
Project Settings > Modules > [library module name] > android > Packaging Tab > "Use resources directory specified at "Structure" section radio button.
Also make sure that "Include assets from dependencies into APK is set.

Related

Libraries with custom attributes conflicting

I am trying to use Shimmer library and a Slider View library together.
Unfortunately, there's a custom attributes in both libraries that is conflicting: I am getting a duplicate attribute found error.
I have read that this is a bug and there are no solutions as of now and we cant create custom attributes within the context of each library. But is there any other way around it apart from me implementing the slider view myself?
Android resource compilation failed
app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4619: error: duplicate value for resource 'attr/shape' with config ''.
\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4619: error: resource previously defined here.
\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml: error: file failed to compile.````
I think there's an workaround for that issue. However, I'm not sure if you can do that due to licensing.
I didn't test it. Not sure if it will work. But I think you can try. If that does not work, let me know and I delete the answer.
To avoid that error, you can resort to the fact that you have access to the source code of the AndroidImageSlider. This way, instead of adding that library as an AAR file, you can import the source code as a module.
This way, you can rename the attr/shape and it will be re-compiled as part of your project.
1) Remove the AndroidImageSlider from your project (from build.gradle etc)
2) Then, create a new module called "library" (File -> Project Structure -> Modules -> + -> Android Library)
3) This will create a new folder to your project <ProjectPath>/library
4) Download the Library Source (using git or as a zip file) and replace the content of the library folder with content from library folder that you downloaded (you can ignore all other folders... You can replace the files of same name).
5) Remove file library/gradle-mvn-push.gradle and remove following line from: library/build.gradle:
apply from: './gradle-mvn-push.gradle'
6) Add following lines to your app/build.gradle
dependencies {
...
implementation project(":library")
...
}
7) Sync and Rebuild your project.
8) Open the file ./library/src/main/res/values/attrs.xml and rename the atribute shape (customShape for example).
9) Try to build again. Some errors may happen since you renamed that attribute. Fix them.
10) You can add the view to your layout as follows:
This will allow you to compile your project. The downside is that you are responsible to fix/update the library by yourself. On the other hand, you have control over the libraries build.gradle and then, you can update the build tools version, support library version etc.
Anyway, this may help you

What is the recommended way to reference an Android library project in Eclipse

One thing that has continued to frustrate me as I learn Android development (via Eclipse) is getting Android app projects that reference Android library projects to work reliably. Sometimes the app project won't build because of missing class references that are defined in the library, and sometimes it builds but then crashes at runtime with the class defined in the library is referenced, with an error link
java.lang.NoClassDefFoundError: com.dave.customviewtestlib.LibTestClass
shown in by logcat.
I'm using Android Developer Tools Build: v21.0.1-543035
I've created a workspace with the simplest possible Android app project referencing the simplest possible Android library project. How exactly am I supposed to tie them together in Eclipse? They both build fine by themselves. Then I edit the "Java Build Path" of the Android app project. The confusing thing is, there seems to be a lot of ways to reference the library project. Sometimes one way works, then it stops working and another way that didn't work before starts working. Am I supposed to
In the app project's Java Build Path | Projects, "Add" the library
project, or
In the app project's Java Build Path | Libraries, "Add Jar" and point to to a .jar containing the library's classes and other resources, or
In the app project's Java Build Path | Libraries, "Add Class Folder" and point to the library project's "bin" folder which contains the classes, or
In the app project's Java Build Path | Source, "Add Folder" and point to the library project's source folder, or
Something else?
Also, there is the mysterious Java Build Path | Order and Export tab. What does that mean?
Also I have a related question: are these so-called Android libraries like static libraries (you reference them at build time and the code gets sucked in, and at runtime it is just part of the app binary), or like dynamic libraries (they can get installed separately on the device)? I understand it's all Java and all classes are loaded at runtime by the class loader, but I think there is still an important distinction. Most tutorials and references are so dumbed-down, getting answers is hopeless.
Any help would really help minimize my irritation :)
In the package explorer view:
Right click on the library project -> project properties -> android tab
Check: Is Library.
Right click on the Android Project -> project properties -> android tab
Click the "add" button, and select your library project from the list.
To answer you "static question" the difference between and Android library project and a jar'd library is that the android tools automatically fixes resource (xml) references for your project (the generated R file, etc) and then it packages the classes into a .jar file and adds it to your project's apk. So it is included statically.
As to your build path and order and export tabs. The build path is where you can add: .jar files, other projects in your work space, and additional source files to your project. The order/export tab from this is where you select what libraries/class files are going to be statically included with your project's jar file (or apk in the case of Android projects).

Android app's reference to android library project broken after Maven->Update Project

I've got an android project and an android library project (my own) it depends on. I'm using maven, including maven-android-plugin, for the automated build, and Eclipse as my IDE, with m2eclipse and m2e-android to bridge the two.
For the most part, it's working fine: I can do a maven build from the command line, and also build from Eclipse.
However, I semi-regularly get a build error in Eclipse for the main android app project that says "Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.". When I do that, it seems to mess up the relative path from the app to the library project in the app's project.properties file. Specifically, the relative path to the library project changes from the correct one to one that reflects the relative position of the projects in the Eclipse workspace.
Example: the disk layout looks like this:
/libs
-- /my-lib
/apps
-- /my-app
Thus the correct relative path from my-app to my-lib is ../../libs/my-lib.
However, in my Eclipse workspace, my-app and my-lib are siblings, and when I do Maven-Update project, it updates project.properties such that the relative path to my-lib (i.e "android.library.reference.1=") becomes "../my-lib".
As a result, in Eclipse, I get compilation errors for all the references in the main app to symbols in the library project. If I then go to the Android properties dialog in Eclipse, in the bottom section where library projects are listed, my library project has a red X next to it. If I remove it and add it back, thus correcting the relative path in project.properties, then everything is fine again.
This is kind of a nuisance. Any idea how to address it? Note: although the changes to the relative path I described are correct, it is only a theory that this is related to the relative position of the projects in the Eclipse workspace -- that could be a coincidence.
This is a known issue and is being currently worked on:
https://github.com/rgladwell/m2e-android/issues/76

Adding a Android Library from a project into the workspace generate a Android Dependencies.Eclipse

When I select the properties to my project then go to Android and add a new Library, the eclipse automatically create a Android Depencies that contains all my .jars.
It does not add the new project to the list of referenced packages. When I try to Run the application I got the error: Conversion to Dalvik format failed with error 1. When i realize I have the .jars that i added both in the Android Dependencies and my /gen.
When I delete de Android Depencies I got error in my classes, saying that i´m not referencing the specifics .jar... But I have them in my /gen past.
Any Ideia how to make the eclipse refer to just one .jar?
Library is a special android feature that allows you to use an apk or another android project where you would for example share some code. It's detailed here :
http://developer.android.com/guide/developing/projects/projects-eclipse.html
I think that what you want to achieve is just adding a jar as a dependency which can be done with Project > Properties > Java Build Path > Libraries Tabs > Add Jars / Add External Jars.
tl;dr :
Project > Properties > Java Build Path > Libraries != Project > Properties > Android > Library
I did these steps to make my app work with the lib-sources using adt 17
add "lib-sources-project" to workspace
import/general/existingProjectsIntoWorkspace
mark this "lib-sources-project" as android library
lib/Properties/Android/IsLibrary must be checked
Add lib to main app
app/buildpath/ConfigureBuildPath/Projects Add "lib-sources-project"
app/buildpath/ConfigureBuildPath/OrderAndExport set check for "lib-sources-project" so your lib will be included into the buildresult
app/Properties/Android/Library Add "lib-sources-project" to the list.
Note since adt 17 you can have resources in your "lib-sources-project". Android Lint will tell you what you have to change to make it work.
Hoever i haven't succeeded yet to include a jar with resources without adding "lib-sources-project" as described above.
Maybe somebode knows how to do this.

java.lang.NoClassDefFoundError - Why? How to troubleshoot?

One of my menu items in my application simply tries to invoke another activity (that belongs to a different project in the same workspace):
myActivity.startActivity(new Intent(myActivity, com.bill.the.App.class));
But that immediately results in an exception at runtime:
E/AndroidRuntime(3847): java.lang.NoClassDefFoundError: com.bill.the.App
Why?
What am I missing?
(the project compiles and build just fine, it's only at run time that this error occurs)
It could be that the project or library containing com.bill.the.App is included in compilation search path, but not included in the resulting apk file (that is deployed to the device). If you include the project or library containing com.bill.the.App using a wrong way, this can happen. Make sure that you include it by using Android Library Project (project properties -> Android) or by including the jar file in the project properties -> Java Build Path -> Libraries.
Just Open your AndroidManiFest.xml, and write following line in it before the </application> tag.
<activity android:name=".App"/>
I had the same problem when importing an old Eclipse/ADT project (made of several projects AKA modules) to Android Studio (2021.3.1.17).
The solution was to right-click the app's module > Open Module Settings > Dependencies > (app's module) > + (Add Dependency) > 3 Module Dependency > Select the module/project that contains the missing class.
The activity may not be registered in the manifest

Categories

Resources