I am trying to add this library to my project because I want to change something in a class there. That is why I adding it as a dependencies in my gradile setting is not enough.
I know that in the library it says "If you want use this library, you only have to download MaterialDesign project, import it into your workspace and add the project as a library in your android project settings.". But what does that mean, should I copy all files and put them in my libs folder ?
Quoting the documentation:
If you want use this library, you only have to download MaterialDesign project, import it into your workspace and add the project as a library in your android project settings.
Step #1: Download the project, whether via the ZIP file that GitHub gives you or by using git to clone the repository
Step #2: Move the MaterialDesign/ directory into your project directory, as a peer of your existing app/ module
Step #3: Modify your settings.gradle in your project directory to include :MaterialDesign in the list of modules to build
Step #4: In your app module's build.gradle file, add compile project(':MaterialDesign') to your dependencies
Related
I am trying to create a Java library in Android Studio. I want to use functionality of another Java library (third party available as a .jar) in it. So I placed the library in libs folder of my java library project and added the following code in build.gradle file:
apply plugin: 'java-library'
dependencies {
implementation files('libs/libraryname.jar')
}
The .jar reference was added successfully and I can use the library methods in my code. My project also compiles successfully and I am able to generate a .jar file of my own java library project.
However, when I am using the generated .jar file in another project and try to access the methods of third party library, I get the following exception:
java.lang.ClassNotFoundException: Didn't find class
"com.packagename.classname" on path: DexPathList[[zip file
"/data/app/com.packagename-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64,
/system/lib64]]
What I have tried
I have tried multiple solutions provided here and here but none of them works.
I have tried to clean and re-build the project and .jar files as well but that doesn't help as well.
I have added the .jar dependency as a module before referring it in my project but it still generates the same error.
Note:
I am using Android Studio 3.1.4
Copy .jar in your libs project folder: change the navigator to project view, than you are able to see libs directory.
Right click on your jar folder inside your project and select add as library, this will automatically import the library on your gradle dependencies
When using Unity3d, "native" (pure-java) Android functionality can be accessed via Plugin. As described in the documentation,
There are several ways to create a Java plugin but the result in each case is that you end up with a .jar file containing the .class files for your plugin
When I create an Android Application Project in eclipse, and set it is a library, it automatically generates a .jar file in the bin folder. I understand that this is a temporary file in the context of the Android toolchain, but this is the file that Unity needs in order to see the classes and build up it's own internal JNI magic. (The entire process is outlined very well here in case more clarity is needed on that process.)
Unfortunately, as near as I can tell, Android Studio does not generate this file. Is there a way I can tell it to give me this file, or perhaps some other way to generate code that Unity will be able to use?
With Unity 5.3+ you no longer need to build a .jar, instead you can use the .aar file that is automatically created by an Android Studio Android Library module. I found this a lot easier than getting the jar method to work:
In your Android Studio project, create an Android Library module: File > New > New Module > Android Library
make sure your minSdkVersion and targetSdkVersion match your Unity project setup
Add your classes etc to the module and build
A successful build should create a .aar file in build/outputs/aar/ e.g. my module creates mkunityplugin-release.aar
Open your Unity project, then drag the .aar file directly onto Assets/Plugins/Android in your Project view. This creates an asset which you can view in the inspector; it will show info on the plugin and the Android platform should be checked
Build your Unity project for Android. My first attempt failed because I had a different targetSdkVersion so I got a build error saying the manifests could not be merged; I fixed that in my Android Studio build.gradle and then it worked
This is where I first heard that .aar could be used directly https://www.reddit.com/r/Unity3D/comments/3eltjz/how_to_add_an_android_library_project_folder_to/
Yes, you can use Android Studio to generate your jars from a Library.
In my case the jar file was located very well hidden in the app build folder, under
<ProjectRootDir>/<AppModuleName>/build/exploded-aar/<ProjectName>/<LibraryModuleName>/unspecified/classes.jar
My example setup for this:
A app module containing nothing but a minimal Android App (Including a MainActivity)
A library module that contains the library code
Add a dependency from your app to your library e.g. add: compile project(':library')
If you build your app now it will also build the library and your apps build folder will contain the jar file under the location I explained above (in my case: PROJECT_ROOT/app/build/exploded-aar/SampleLibrary/library/unspecified/classes.jar).
You can create a jar file using Android Studio.
Just add these tasks in your app's build.gradle file.
//task to delete the old jar
task deleteOldJar(type: Delete) {
delete 'build/libs/AndroidPlugin.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
///Give whatever name you want to give
rename('classes.jar', 'AndroidPlugin.jar')
}
exportJar.dependsOn(deleteOldJar, build)
Once you add the above lines you can export the jar using the task of the same name.
You can go through this post on TGC here on how to create an Android Plugin For Unity using Android Studio
Simple way:
Create new Android Studio Project
File > New > New Module and select Android Library
Copy <UnityPath>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes\classes.jar to <project path>\<Android Library Module name>\compileOnly (create this folder before)
Add this jar as Library
Open this Module Settings
Set Compile Only
Build > Make Module <Android Library Module name>
Result
Jar-path: <project path>\<Android Library Module name>\build\intermediates\intermediate-jars\debug\classes.jar
Aar-path: <project path>\<Android Library Module name>\build\outputs\aar
Change apply plugin: 'com.android.application' to apply plugin: 'com.android.library'. In the build.gradle under app.
I'm not really sure about Android Studio but in ADT I use the export functionality by right-clicking on the project. With this you can create your .jar and place it wherever you want. Unity needs it to be on a specific folder to see it when running on a device (unfortunately I don't remember it well, but it should be something like Assets/Plugins/Android).
I want to use a svg-android library to work with *.svg files in Android. For the same, I've installed the apache ant, created a folder in workspace called: SVGAndroid and then added
android.library.reference.1=C:\Android\workspace\SVGAndroid
to project.properties file.
There were no documentation for functions in ReadMe, so I'm wondering if the installation correct or not, how to reinstall an external lib in the second case and where are the examples of using svg-android?
For your including of the project, just include the project into your workspace and in your respective application under the properties of that project just add a dependency on a library that references svgandroid. Make SURE to include the files and ensure that the compile class files are present in the final output of the apk. This typically means that you add the project to your build path/order.
Another approach is to just take the entire project and compile it into a jar file and then include that jar in your libs folder and add that dependency on the jar file of that respective project to your core application.
Useful links
How can I use external JARs in an Android project?
I would rather suggest to not add the path to the project manually, but from Project Properties -> Android and you will have a list with all the library projects in the workspace from which you can choose the desired project.
Also I suggest adding in project.properties the following line:
manifestmerger.enabled=true
in order to have all the AndroidManifest.xml files of the referenced library projects merged into the main project's manifest.
If you want to include a library file in to your project follow the below steps;
Download a jar file and save it in any folder.
open your project.
Right click--> Build path--> Add External Archives---> Add your external jar file to your project
Is there a way to include a library project in a project without it being a separate project? The ideal situation is to be able to make code changes to the library project and push it to the git repo with the main referencing project.
You can add libraries to your build path.
You can export the library project as a jar file and then you can add that jar file in your libs folder and configure your build path to add it to your project.
I have created an Android project and added an external JAR (hessian-4.0.1.jar) to my project. I then added the JAR to the build path and checked it off in Order and Export.
Order and Export is ignored it seems, and all classes from the external JAR are missing at runtime.
Is there a trick to properly include the needed classes from an external JAR when building an Android application using the Eclipse plugin? I do not want to use ant or Maven.
For Eclipse
A good way to add external JARs to your Android project or any Java project is:
Create a folder called libs in your project's root folder
Copy your JAR files to the libs folder
Now right click on the Jar file and then select Build Path > Add to Build
Path, which will create a folder called 'Referenced Libraries' within your
project
By doing this, you will not
lose your libraries that are being referenced on your
hard drive whenever you transfer your project to another computer.
For Android Studio
If you are in Android View in project explorer, change it to Project view as below
Right click the desired module where you would like to add the external library, then select New > Directroy and name it as 'libs'
Now copy the blah_blah.jar into the 'libs' folder
Right click the blah_blah.jar, Then select 'Add as Library..'. This will automatically add and entry in build.gradle as compile files('libs/blah_blah.jar') and sync the gradle. And you are done
Please Note : If you are using 3rd party libraries then it is better to use transitive dependencies where Gradle script automatically downloads the JAR and the dependency JAR when gradle script run.
Ex : compile 'com.google.android.gms:play-services-ads:9.4.0'
Read more about Gradle Dependency Mangement
Yes, you can use it. Here is how:
Your Project -> right click -> Import -> File System -> yourjar.jar
Your Project -> right click -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
This video might be useful in case you are having some issues.
I know the OP ends his question with reference to the Eclipse plugin, but I arrived here with a search that didn't specify Eclipse. So here goes for Android Studio:
Add jar file to libs directory (such as copy/paste)
Right-Click on jar file and select "Add as Library..."
click "Ok" on next dialog or renamed if you choose to.
That's it!
I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.
The reason that hessdroid works where hess failed is because the two jar files contain java that is compiled for different virtual machines. The byte code created by the Java compiler is not guaranteed to run on the Dalvik virtual machine. The byte code created by the Android compiler is not guaranteed to run on the Java virtual machine.
In my case I had access to the source code and was able to create an Android jar file for it using the method that I described here: https://stackoverflow.com/a/13144382/545064
Turns out I have not looked good enough at my stack trace, the problem is not that the external JAR is not included.
The problem is that Android platform is missing javax.naming.* and many other packages that the external JAR has dependencies too.
Adding external JAR files, and setting Order and Export in Eclipse works as expected with Android projects.
Goto Current Project
RightClick->Properties->Java Build Path->Add Jar Files into Libraries -> Click OK
Then it is added into the Referenced Libraries File in your Current Project .
Android's Java API does not support javax.naming.* and many other javax.* stuff. You need to include the dependencies as separate jars.
If using Android Studio, do the following (I've copied and modified #Vinayak Bs answer):
Select the Project view in the Project sideview (instead of Packages or Android)
Create a folder called libs in your project's root folder
Copy your JAR files to the libs folder
The sideview will be updated and the JAR files will show up in your project
Now right click on each JAR file you want to import and then select "Add as Library...", which will include it in your project
After that, all you need to do is reference the new classes in your code, eg. import javax.mail.*
in android studio if using gradle
add this to build.gradle
compile fileTree(dir: 'libs', include: ['*.jar'])
and add the jar file to libs folder
If you are using gradle build system, follow these steps:
put jar files inside respective libs folder of your android app. You will generally find it at Project > app > libs. If libs folder is missing, create one.
add this to your build.gradle file your app. (Not to your Project's build.gradle)
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// other dependencies
}
This will include all your jar files available in libs folder.
If don't want to include all jar files, then you can add it individually.
compile fileTree(dir: 'libs', include: 'file.jar')
create a folder (like lib) inside your project, copy your jar to that folder.
now go to configure build path from right click on project, there in build path select
'add jar' browse to the folder you created and pick the jar.
Copying the .jar file into the Android project's folder isn't always possible.
Especially if it's an output of another project in your workspace, and it keeps getting updated.
To solve this you'll have to add the jar as a linked file to your project, instead of importing it (which will copy it locally).
In the UI choose:
Project -> Import -> File System -> yourjar.jar -> (Options area) Advanced -> Create link in workspace.
The link is save in the .project file:
<linkedResources>
<link>
<name>yourjar.jar</name>
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/bin/android_ndk10d_armeabi-v7a/yourjar.jar</locationURI>
</link>
</linkedResources>
PARENT-5-PROJECT_LOC means relative to the project file, 5 directories up (../../../../../).
Then add it to the libraries:
Project -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
In the same window choose the Order and Export tab and mark your jar so it will be added to the apk.