I have developed an Android library which also contains native code.
My native code dynamically links to another library. So I added this into my CMakeList.txt:
target_link_libraries(sysnative /path/to/libexample.so)
The problem is Android Studio will copy libexample.so into the .aar file.
I don't want this. I have other projects using libexample.so.
If each of my projects have libexample.so in the aar file, I will have it multiple times.
Related
I have own Android library which use 2 external libraries:
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
When I use my libary in another project app crashes and shows error related to these two libraries.
How I can generate .aar file of my library which will include these two libraries.
Right now I need to add these dependiencies manually in my another project and I want to avaoid that
I have an android app using android libraries (dependencies in build.gradle), that I want to use in Xamarin Forms app.
I have prepared android class library with dependencies that I need, add it to Android app and it works as should. Now I want to extract library (not app) - .aar file or other type. Then in Visual Studio create android binding library project, add android library (f.e. aar) under "Jars" folder, compile .dll file and in Xamarin Forms project, add reference to .dll and get needed functionality.
Xamarin app accept binding library, it knows android studio library package, tries to execute method, but then problem occurs "Java.Lang.NoClassDefFoundError". Aar is very light about 40KB, seems like it does not include the library I need, but just reference. Is there a way, that I can have those methods in dll library? I have tried exporting .jar file (weight about 2 MB) but it is also missing classes.
Target Application: Development of an Unity application for android device.The Unity application will use OpenCV for various image processing functions.
Approach Planned:
Develop an OpenCV for android application in Android Studio. This will have a bridge class for sharing data with Unity.
Export the android studio project into jar
Use the jar and other assets in Unity as a Plugin
Access the required functions for image processing using the bridge class in android using the Android Java support classes in Unity.
Build the unity application for Android Platform
Experiments Done:
Already did a set up for OpenCV for android in Android Studio.
Tested sample applications on device by generating apk.
Tested the plugin concepts in unity using DLLs for a windows based application. Dll concepts working fine for Unity.
Final Experiment--
4. Used the classes.jar generated in the build\intermediates\exploded-aar... as a plugin in Unity.
It generates an apk from the unity build. The apk gets installed on a device but fails to open.(Can't see it in the apps menu)
Used this .jar approach based on an answer in the following link
How to export library to Jar in Android Studio?
Problems:
Most of the android plugin tutorials use Eclispe and have the export to jar function. This jar file can be used as a plugin in unity.
Queries:
I found about the jar task which could be included in the gradle script.
But I am not sure how to use it ? There seems to be a lot of version for the jar task creation in Android studio. How to achieve for a project using opencv in android?
I am also confused whether .jar or .aar will solve my purpose?
Should I try any other approach like the android library for achieving the android, Opencv and unity integration.
My take on Solutions:
Generating the appropriate jar in Android Studio will solve the issues.
Else go back developing the opencv for android in eclipse
Useful Links
Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?
The following project approach is almost the same which I want to acheive
https://github.com/thorikawa/unity-opencv-android
Any help on this will be appreciated.
Update 24th Feb 2015
With the help of this link
Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?
I am able to integrate Unity and Android.
The android studio project now contains two classes an activity class and a normal java class containing various getter functions.
I am able to call any functions of the normal java class from unity.
But unable to start the activity class from unity.
My Thoughts
I guess unity generates its own manifest file while doing a build for android in unity.
Changing the android studio manifest file accordingly might solve the issues.
Queries
How to start an activity inside the android library from Unity?
How is the android studio generated manifest file provided in unity so that unity merges it with its own generated manifest without any conflicts?
Things Tried
While building in unity, if no android studio generated manifest file is provided, the app functions properly and communicates with the simple java class with getter functions.The values can be obtained in Unity.
If the default manifest file is provided along with the classes.jar the app gets installed but crashes on opening. Even the app name is changed to the one provided by the android studio manifest file.
If any one could help me with this I ll be grateful. Besides I think if I solve this step integrating opencv for android won't be very tough.
Best regards,
Swaroop
First of all you can’t use .aar files unless you have Unity5 (I don’t have but I read that aar support is added). For creating jar I use the same approach that use posted here and it worked for me.
If you have Unity5, If your project is set up as an Android library, it will output an .aar when it's built. It will show up in the build/outputs/aar/ directory in your module's directory.You need to copy those to Assets/Plugins/Android folder
If you want to open an activity from Unity since you added it inside your .jar need to declare it inside your manifest. If you are already using a custom manifest for your project just add it inside your application tag.
Otherwise you need to create a custom manifest for your project. First you need copy the Android Manifest that Unity generates when you compile your game, it’s on folder:
YourProjectname/Temp/StagingArea/AndroidManifest.xml
copy it from there to Assets/Plugins/Android folder inside Unity and add your activity of your library:
<activity android:name="yourLibraryPackagename.YourActivity"</activity>
into that manifest inside your application tag and you should be able to open your activity.
I'm new to android development. I wanted to implement Navigation Drawer feature in my application, which requires android.support.v4.jar file to be included in my project. I'm using Android Studio to develop my application so I included the compile "com.android.support:support-v4:18.0.+" in my build.gradle file as mentioned in https://developer.android.com/tools/support-library/setup.html. My project is working fine, I was able to successfully include my library. I did adding library without resources.
What I couldn't figure out is the difference between adding library without resources and adding library with resources. Does adding library with resources mean including some sample project?
Thanks
For Android Studio projects using Gradle (which is what your project is), there isn't an important distinction between libraries with resources and without resources. The Gradle build system's support for Android is more advanced than anything available to Eclipse and can support libraries with and without resources the same way (you just add the compile statement to your dependencies as you have; you can also do it more easily via the Project Structure dialog).
In Eclipse, if you want to include a library with resources, you have to add it as a project (similar to an Android Studio module) to ensure the resources get included directly; there you can't include resourceful libraries as simple jar files.
I have read the overview for Android Library project. I have in mind to develop an Android project library containing native libraries and JNI wrapper which would be included into the Android project. However, the doc does not explicitly mention if Android library project can include native libraries.
Can anyone confirm/infirm support for native libraries in Android library projects ?
As Android Document said:
An Android library project is a development project that holds shared
Android source code and resources.
An Android Library Project, in fact, isn't so different from normal Android project. You can make a normal android project as library project, except asset folder. They're just different when you declare in Eclipse Buid Path or something similar in other IDEs.
Native support simply, just a call to native layer (as in your post, Native Library) such as C/C++ library file (*.so file). This function is not specific to Android, but in normal Java project also support this feature: Calling functions from another language inside Java.
So, in short answer, yes :)