i know we can convert a java class file into a jar file , but i want to know , is there any way to convert a whole Android Package into a jar file or another format , so i can use them in another project ?
and if with any way we can convert it , and the main app has some permissions , are they added to second app or i must add them in second app manifest ?
You can create an Android Archive Library i.e. an AAR file (*.aar) if you make your project a library. As far as I know a JAR file cannot contain all the Android specific components of the project. You can find a very brief JAR/AAR comparison in this discussion.
You can have a look at these tutorials by Vogella and Android By Code for creating such a library and you may find relevant Stackoverflow discussions with the "aar" tag. But as this is a rather new feature and support in Android Studio (or Eclipse ADT) has improved from version to version some of the older discussion might not be up-to-date anymore.
The permissions specified in the library's manifest will apply to the library code even in the app. that is using the library. Commonsware has explained the manifest aspect in more detail.
Firstly, you must go in Eclipse, to File -> Export -> Java (jar file) -> and there you select the package you want to export as a .jar file.
Concerning your second question, you must add the permissions again to the second application.
Related
I'm trying to setup the Scichart libraries using this guide.
The library I downloaded has a structure that looks like this:
I copied the 5 .aar files and the 4 documentation .jar files into the libs folder of the app in Android Studio, like so:
Following a guide I read online (I've never added an external library before) I found that for the documentation to work I'd need to add it as an attachment here:
However, when I right clicked and went to library properties it looked like it already had it - I assume that since the files are in the lib folder in the app they're seen and used.
So, everything should work. The problem is that Android Studio is offering to import one of two classes with the exact same package name but different Gradle packages (? don't know if that's the right term) on the right. Picture:
Why is it doing this? What did I do wrong when adding the library?
Per tutorial (Tutorial 01), the sections
Using Maven (well it's more Gradle)
Using bare SciChart libs
Are mutually exclusive.
If you already referenced their libraries via build.gradle (as described in the tutorial, Using Maven part), you don't need (and don't have) to put JAR(s) inside any folder and then add them to the Module settings, or whatever. Even sources will be pulled down automatically.
What you're doing is creating a local repository, in addition to using the remote one. That's why the duplicated libraries.
i've been searching all the web for a definitive solution for this simple problem of adding an external directory with .java files and .jar libraries to my Android Studio project.
Here's what I want to do:
Create a default project in Android Studio, and import from git the library I will work on, which is a bunch of .java files and a .jar (jsoup). These java files need this jsoup. The java files are not for Android, just simple java files.
I need it to be from github because I'm working on this lib and I need AndroidStudio to automatically update it to its newest version.
This is how I compile my project:
javac -cp ".:jsoup-1.8.3.jar" Main.java Class1.java Class2.java;
Then I run:
java -cp ".:jsoup-1.8.3.jar" Main
Well, I already loaded this library from github using Android Studio, so now I have:
Project/app/src/main/java/com.myname.myapp
Project/MyLibraryFromGithub
Of course I seen answers like this and I followed everything, but there are some problems. For example, it kept searching for a AndroidManifest.xml file which I don't know how to write because it's a simple java project, not a Android Project. Also, I think this answer is outdated, and won't work properly in AndroidStudio 2.0.
I've read some tutorials on Gradle but it won't say anything about external folders and so. Also, when I make it happen, how do I import my library? For example, in
Project/app/src/main/java/com.myname.myapp/Main.java
How do I import the library? import myLibrary? Or I just need to create new objects with the classe's names? Like Class1 myObject = new...?
This is so congusing! I whish I could compile everything by hand, Gradle is hiding too much from me and I can't find a good tutorial.
To add an external jar to your project you should do the following steps:
Select File >> New >> New Module.
Select Import JAR/AAR Package.
Give the file name in the File name text box and click on Finish.
Select File >> Project Structure.
Select app under the modules section on the left hand side.
Choose Dependencies tab at the top.
Click on the + on the right hand side.
Select Module Dependency
Select the JAR file that you have just imported.
Close both the open windows by clicking OK
Have you tried this?
Place X.jar into the libs folder
Right click on X.jar and 'Add as Library'
(In build.gradle) Place this in dependencies: compile files('libs/X.jar')
I Have a AAR file , in Mobile First Project I have to do a call which should open the activity from AAR file . How to do that? I have a Eclipse with MFP 7.0 .
As suggested by Andrew in the comments, there is nothing specifically in the MobileFirst framework that will help you here. You will need to write native code in order to use whatever is inside the AAR file.
Create a Cordova plug-in as described in the following tutorial in order to access the AAR file and use its provided functionality: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/adding-native-functionality/android-adding-native-functionality-hybrid-application-apache-cordova-plugin/
However I believe this may also require handling it via Gradle: cordova plugin add external .aar file (not .jar)
Another suggestion that comes up is to extract the .jar file that is inside the AAR file and then that's much easier to handle...
I have a Android library project need to convert this in to a jar file and use it on my Android project.like we are doing on Adds network integrations,Is there any way to achieve this?.
An Android project can't really fit into a .jar file, unless you just wanna use the compiled java files, which you would certainly have done it via a normal Java library project instead of a Android Library Project in first place.
Android Library Projects are packaged into aar files. Read more about it here: http://tools.android.com/tech-docs/new-build-system/aar-format and it is automatically handled by Gradle builds and late Android Maven scripts...this last one used to use a 'apklib' format which has been deprecated to be replaced by aar format. You can read more about it here: https://code.google.com/p/maven-android-plugin/wiki/ApkLib
I've done this before.
But, due to my requirements, i only needed implementation (no android specific resources). Although you can still include Android actual code (if the project you're going to use it in is also an Android project in which you can load the SDK which includes the classes you're exporting in the jar)
Now the .jar file that is automatically generated in the bin folder, will not allow you to do this because it includes all the Android's project resources (which is not understood in the Jar format). Therefore, you must exclude all except the src folder. Note : Make sure you also exclude the files in the root folder of the project (i.e, AndroidManifest.xml, etc .. )
In Eclipse : Project properties -> Export -> Jar -> (Include only src folder)
If you're project library includes native code ( NDK ), there is a few other workaround that you need to do to get it to work. If this is the case, comment below, i'll help you out.
Cheers
I'm not actually working on android devices, but I'd like to use the android java std lib for a project of mine. I'm extracting the android java std lib from the android ADT here:
http://developer.android.com/sdk/index.html
After unzipping the bundle, it's in
adt-bundle-windows-x86_64-20130729\sdk\platforms\android-18\android.jar
However, when I open this up in Intellij, it doesn't show any source code: all methods are just labelled as "compiled code"
Is there any way to get the source code (in a jar or otherwise) for the android.jar so I can hook it up to the IDE so I can nicely browse the source code of the standard library? I've dug through the sdk download bundle and haven't found anything.
-Haoyi
but I'd like to use the android java std lib for a project of mine
I have no idea why you think that would work, any more than trying to use a Windows DLL on Linux.
Is there any way to get the source code (in a jar or otherwise) for the android.jar so I can hook it up to the IDE so I can nicely browse the source code of the standard library?
The source code for Android is at the Android Open Source Project. The source code for the android.jar is mostly in the platform_frameworks_base repo (GitHub mirror), but the JAR is really an output of a firmware build.
In your Android SDK root directory, go to the sources folder. Here you will find the source files for the different platforms you have downloaded.
Note: This gives you the Java code for Android libraries such as Activity
Unpacking the jar is way more than you need to worry about. Android is open source, so you can get everything you need online. To start, you can browse most of the source on Android's GitHub account, or download the source tree on the Android Open Source Project website. You can also view most (if not all) sources on GrepCode.
If you really want to go through the trouble of extracting the jar and decompiling the source, you can use JD-GUI.
As you use eclipse, use
jadclipse
which extrach any jar that in eclipse, u can view any source code with out download and also without internet. It has also export source code, As a developer It help u most times. :->
link to download