Connecting AAR with Mobile First application - java

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...

Related

Convert a whole android package to jar file in eclipse

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.

How to create jar file from Android Library project

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

Referencing library inside of library from Android APP Manifest

I have an app project, which uses a library (referencing the library project, not using a jar). Inside that first library, I want to use another library (Estimate Beacons Library), this time using a jar inside the first library libs folder. To properly use this second library, I need to declare in the manifest the following service:
<service android:name="com.estimote.sdk.service.BeaconService"
android:exported="false"/>
I have tried declaring this service in the APP project manifest, but it doesn't get it. The same using the first library project manifest (normal, if I'm not wrong this manifest is ignored by the compiler?).
Any help would be much appreciated. I've been looking for a similar issue but I didn't get lucky.
Edit:
Even with the following configuration it does not work:
First library has Estimote Beacon SDK (second library) added in lib folder. Also, it has bluetooth permissions and service declared in the manifest.
APP project has first library (not using jar but referencing the project) and second library in its lib folder. Bluetooth permissions and service is declared in the manifest.
I also created a test app, declaring the service and bluetooth permissions, and adding the library in the lib folder and it worked great, so it is just getting confused when I use my library.
AndroidManifest.xml it's just Application configuration file, but not build file.
If you are using Gradle build system, than your libraries dependencies should be specified in build.grale and settings.gradle files.
Read this Building Your Android Project with Gradle
Try enabling manifest merging in the project.properties file:
manifestmerger.enabled=true
Also check your generated manifest in the bin directory after you build your project, and make sure the service definition is there.
This is the approach that works for the Android Beacon Library, and I have used it to make other libraries dependent upon it.
Ultimately, though, it is true that Android Studio provides more flexible tools to do this.

How to get source code for android.jar

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

How can I export the libs of a project in the jar?

I'm making an Android library to implement generalized OAuth Authentication(both 1.0a and 2.0). I'm using the signpost libraries for signing the Http Requests. Now when I try to export my project as a .jar file(using Eclipse, right click on Project->Export->Java->Jar file), the jar gets created successfully, but it hasn't exported the signpost libraries.
When I open the .jar file, I find that the libraries are present, but they aren't visible to the project I'm importing it in. How can I expose these libraries from the jar?
EDIT: Once I import the library into my test application and call the function, OAuthFactory#authorize() (A custom class that handles OAuth authentication), I get the following compile error: The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files.
this question has also been discussed here.
How to combine library with my jar?
Of course, you can extract the library-jars and add the extracted class-files into your own jar,
but you would lose the clear view to the external lib's versions this way.
The solution that works best for me is to ship your JAR-file with an additional folder that contains all external JAR-Files and then refer to them in your /META-INF/MANIFEST.MF:
Class-Path: lib/kxml2-2.3.0.jar lib/log4j-1.2.16.jar
You can leave the JAR-Files external this way and won't have to blow up your own JAR-file.
Greetings
Christopher

Categories

Resources