I have an android project that contains only a .java file. This java file extends the class Services.
I am trying to build a jar file using * *Build Fat JAR**.
I did the following:
right click the project -> select Fat Jar and inside the Configure Fat Jar Plug-In I've selected the OPTION: select Manifest file. With next-> finish I've managed to create the .far file.
PROBLEMS:
The jar icon has a red x mark in front of it. When adding the jar inside another project and when running the application (creating apk) I get the following:
Dx trouble writing output: invalid header field. Conversion to Dalvik format failed with error 3
What am I doing wrong?
Need some help.
Thank yiu
To Create a JAR from a Android project follow below steps
Project -> Properties -> Android -> Check 'Is Library' option.
Now build Project and get jar in 'bin' folder.
Related
I have created a library module in my project. Now, I want to share/publish this library with others. Sharing a .aar file would be fine for now.
I went through the article -
https://developer.android.com/studio/projects/android-library and found the following options.
When you want to build the AAR file, select the library module in the Project window and then click Build > Build APK.
However, if you want to share your AAR file separately, you can find it in project-name/module-name/build/outputs/aar/ and you can regenerate it by clicking Build > Make Project.
I have tried these two options, but couldn't find /aar folder in the path project-name/module-name/build/outputs/
This is the first time I am building a library that needs to be shared with others.
Is there something else I need to do? Please share your thoughts.
You should do it using gradle. Just follow these steps and you will get .aar file:
1) At right side of your android studio there is a pane name Gradle. Open it and then do open library portion and run assemble. Like in the picture below.
2) When it is successfully ran just go to your library folder and you will find your .aar files there.
C:\projectPath\libraryPath\build\outputs\aar
You can try manually create .aar from command line
./gradlew <moduleName>:assemble
output is located
<project_path>/build/outputs/aar/<module_name>-<build_variant>.aar
[Read more]
I have added Facebook SDK and Google-play-services_lib as library in my project . I have deleted android-support-v4.jar from my project Lib folder. Now I am facing with following problem
[2014-09-26 15:47:47 - Dex Loader] Unable to execute dex: Multiple DEX files define Lcom/facebook/android/AsyncFacebookRunner$1;
[2014-09-26 15:47:47 - Mmatching] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/facebook/android/AsyncFacebookRunner$1;
This means that you have multiple files defined for your project settings.
For that,
Go to the,
Project Properties -> Java build path -> Libraries -> Remove Android dependencies
To be more specific -
Just removing the facebook-android-sdk.jar file from libs worked for me as well as it refers to the facebook related jar which I had in multiple.
Remove this error by following these steps:
Right click on the project and open the properties.
Go to 'Java Build Path..'
Go to Order & Export tab. Unmark 'Android Private Libraries' & Click 'OK'.
and clean your project. It works.
Just Uncheck your Android Dependencies checkbox from Java Build Path -> Order and Export.
I made a project as a library and now I want to export it in order to use it in others projects. Usually I just take the .jar generated but this time it doesn't work.
I included the .jar like this :
Right click on the project > Build path > Configure build path > Add external jar's
When I use my library, eclipse seems to recognize the classes in the .java files...
I think the problem come from the XML file because when I type the beginning of the class name, eclipse does not offer me the rest like it does with the native classes...
Also in the logcat this error has drawn my attention :
07-23 18:30:52.913: I/dalvikvm(4366): Failed resolving Lcom/example/test/MainActivity; interface 1000 'Lcom/omaflak/pulltorefresh/PullToRefresh$OnStartRefreshListener;'
Someone to help please ?
Right click on your project -> Properties -> Android -> check the "Is Library" box. Now your project can be referenced in other projects when you specify so in the build path.
Another thing you could do is right click-> export, and choose JAR file from the wizard.
Using this method only pulls the classes though. It doesn't seem to pull any layouts/XML
i've been struggling with this issue for a couple of days now...
ill explain my problem in a nutshell....
i have a simple java project (not android library or something more complex) which i want to use as my model..
lets assum it is called mymodel and it has a simple class Model.
i also have an android application myandroidapp and in the main activity i want to create an instance of the class Model.
I can add the mymodel as a project to the build path and compile but when i run this application it throws class not found exception. how can i make it work?
please help.
thanks
Step #1: Create a JAR based on your "simple java project"
Step #2: Put the JAR in the libs/ directory of your Android project
And you're done.
Never mess with the build path of an Android Eclipse project manually.
In Eclipse, you can follow the following steps:
Creating JAR file
Right-click on the root of the mymodel project and click on 'Export...'
In the window that appears, expand the 'Java' category/folder, choose 'JAR file' and click 'Next'
In the next window, choose the options you desire, especially pay attention to where the 'export destination' is. When you're done, click on 'Finish'. The JAR file will now be located at the 'export destination'.
Adding JAR to Android project
In your android project (myandroidapp), copy the JAR file into the libs/ folder. You can do this by simply copy and pasting or dragging and dropping etc.
Then, right-click on the JAR file that is now in the libs folder, go on 'Build Path' and from the menu that appears, click on 'Add to Build Path'
You should now be able to use this JAR file in your Android project.
I want to create a jar file from one android project for another android project.I want select only certain classes not all classes from project.I tried eclipse-export way to create a jar.Jar file is created and it also contains all selected class files,after adding the created jar file to the main android project it gives the error:“java.lang.NoClassDefFoundError”.Is the eclipse-export way is not valid to create jar for android project?
I also tried steps provided by this blog http://www.olivacorner.com/2011/04/create-an-android-jar-library-with-eclipse/comment-page-1/#comment-343,but not able to create a desired jar file.
Can anybody please provide the steps to create a jar file for android project.
Thanks.
So you want to create a library for Android? In this case, you can create a Library-project and then reference to it in the main-project.
See the docs.
Step 1. Create Android library project as explained here.(Same as suggested by Lukas)
Step 2. Now you need to give reference of Android Library project created in step 1 to your client application. There are two ways to do so.
Give reference of Android Library Project itself by client app property -> Select 'Android' on left pane -> In Libraty Section, Add Android Libraty project (This is explained at link given in Step 1 above)
Give the reference of .jar file of Android Library project (from Location of Android Library project -> bin -> .jar file). Client Application -> Properties -> Click 'Java Build Path' in lefe pane -> Go to 'Libraries' Tab -> Click 'Add External JARs' button and select the .jar file -> Go to 'Order and Export' tab and select the added .jar file reference and move it to top.
Hope this will help you.