i am using the android ndk with the new gradle-experimental plugin. Now i have my project structure like this:
module with java and c++ code
app with java and c++ code
Both are in one android studio project. Now my app c++ classes have dependencies to the module headers. I want to modify my build.gradle so that the headers i want to export are automatically exported (all headers in a file structure usually).
Can you give me a hint what the best way is to realize this? I will use this a lot so a beautiful solution with a bit more work is prefered.
I am thinking of a way to put headers inside the aar file, so that they are under the "exploded-aar" folder, where i can reimport them from my app.
Related
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 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.
I'm attempting to build an android app in Android Studio that integrates the jReddit Java Wrapper. I've cloned the git repository, added a build.gradle file, added the proper dependencies and referenced the jReddit module in my android app's project structure.
I'm able to create any of the objects in the jReddit library, but I cannot use any of the methods for those objects. I get a "Cannot resolve symbol 'xxx'" when I try to use a method. Currently the project structure is set up like below:
Project Title
App
src
libs
jReddit
src
libs
So the app's code is in the src folder and any .jar dependencies are in the libs folder. The jReddit project has in it's build.gradle file "apply plugin: 'java'" and is listed as a dependency in the app's build.gradle file. Finally the libs folder in the jReddit project tree has the jars that IT depends on (which are also referenced in its respective build gradle).
Ultimately, everything compiles nicely, is imported nicely (in the app source code), there are no errors instantiating a new object from the jReddit library, but when I go to do anything with that object, Android Studio cannot find any methods. See the screen shots below to see what I'm talking about:
http://i.imgur.com/Hm09S3W.png
I'm completely dumbfounded with what to do here. I've never encountered anything like this. Does anyone have any suggestions?
So this is a very old post but I never followed up on this. It turns out, I had done everything correctly, but I was attempting to access the objects methods outside the scope of a function (either main or otherwise). Moving the code into the main function fixed the issue.
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 have a question regarding how to obfuscate an Android library project. Overall, I'd like to obfuscate an apklib file (or really the .java files for any library project) that contains both .java files (in the Android src/ directory) and XML files / external resources (in the Android res/ directory). I'd like to be able to distribute this library to other developers, similarly to the Facebook SDK library (https://github.com/facebook/facebook-android-sdk for reference). However, I want the code to be obfuscated so that my methods aren't exposed in an easy to read manner.
I've tried using Proguard with Maven, but even after building my project with Proguard the files in my .apklib were not obfuscated. I also tried running Proguard manually, but I wasn't able to have it output raw .java files (that could be referenced by another project as a library) instead of .class files.
If anybody has any information on how to obfuscate the java code in an apklib / Android library, I'd be very grateful. Additionally, it would also be very helpful to know if it isn't possible to create an obfuscated andoroid library at all.
Thanks very much for your help.
Best,
Kevin
Depending on how you set up the proguard goal of the android maven plugin you can most likely create an apklib that is obfuscated. I have however not tried myself. Keep in mind that proguard obfuscates into a secondary artifact potentially and not into the primary apklib.
You should also keep in mind that if you obfuscate the library your users will have to use the obfuscated method names... which sort of defeats the purposed of the distribution and will make it very hard to use so it might be a bad idea. The only thing this would work is if you obfuscate all the code without obfuscating any public method and class names..