I am fairly new to android studio, and I am trying to export a jar out of an Android Studio project for another Unity project.
I followed the instruction given on the link Create An Android Plugin For Unity Using Android Studio
But whenever I'm trying to export its showing "Build Successful" and "External task execution finished 'exportJar'" but I am not able to find any jar in specified folder of gradle file.
I looked into the folders "app/release" its empty and "app/build/intermediates/bundles/release/" contains only another folder named "instant-run".
So I am bit confused whether I am skipping any step or looking on the wrong path.
I m using Android Studio v2.1.2
App.build file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.merchantapp"
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.1'
compile files('libs/PGSDK_v1.0.jar')
compile files('libs/classes.jar')
}
task deleteOldJar(type: Delete) {
delete 'release/AndroidPlugin.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
///Rename the jar
rename('classes.jar', 'AndroidPlugin.jar')
}
exportJar.dependsOn(deleteOldJar, build)
android {
lintOptions {
abortOnError true
}
}
you should change this line
apply plugin: 'com.android.application'
to
apply plugin: 'com.android.library'
it is mandatory. and then rebuild your project.
cause we are generating library and it should required for build jar file.
reference How to export library to Jar in Android Studio?
Related
The reason I need this is because I'm trying to work around what I'm told is a bug with Xamarin not always closing streams and thus not writing to some content providers. The technique is to create a jar and then run a script to C#ifiy it and export it to a dll. That's why I need a jar.
I initially tried this by creating a Java Library but that didn't work because I need access to various android packages (for example, android.Net). So while I did manage to create a jar for a Java Library following these instructions (Abhinav Tyagi's answer) I can't seem to get it to work for an Android Library. For an Android Library it says it ran the Create Jar script but I don't see it.
To be clear, this is what I would like to turn into a jar:
Export jar file using Android Studio
Check out the library source code from the repository.
Import checkout library in your android studio.
Modify your build.gradle
If your current module is a library project then you need to properly recognize ‘android-library’ plugin as mention below.
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:16'
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'myLib.jar')
into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
delete 'build/libs/myLib.jar'
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:16'
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'myLib.jar')
into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
delete 'build/libs/myLib.jar'
}
Run gradlew to make jar.
For generating .jar, follow below steps,
Open the terminal.
Move to your project root directory.
Call makejar function which you have added in build.gradle
Example :-> D:\Users\MyWorkspace\project > gradlew makejar
After following all above steps you will find “myLib.jar” under release folder.
How to create JAR file from Android Studio also referencing res/ folder? Below is my graddle. As of now it contains "include('classes.jar')" inside "task exportJar". Is it possible to also add resource folder?
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jniLibs
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
//task to delete the old jar
task deleteOldJar(type: Delete){
delete 'release/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 to give
rename('classes.jar', 'Executable.jar')
}
exportJar.dependsOn(deleteOldJar, build)
To properly include resources, manifest entries, assets, in addition to compiled code, you need to create an android library which exports an AAR file (not a JAR).
You do this with an Android Library. You can create one using Android Studio with File -> New -> Module and select Android Library. You'll notice that the build.gradle it creates has apply plugin: 'com.android.library' which tells gradle that it's going to build an aar instead of an app. Other app projects can then include this aar to merge all the library resources into its own.
This application is a customized View which has a 3d effect:
enter image description here
Please notice the contents which are surrounded by the red box.
*.so is a C++ SDK which contains some 3d animation effects.
I want to make this whole project into a widget SDK, so I can simply reuse it in my other project.
Could anybody give me some suggestions how to make it happened?
Here is my build.gradle, unfortunately this gradle export a jar I can not use, which I think the reason that it is lacked of *.so.
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets{
main{
jniLibs.srcDirs=['libs']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
//task to delete the old jar
task deleteOldJar(type:Delete){
delete 'release/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','icreatorSDK.jar')
}
exportJar.dependsOn(deleteOldJar,build)
Waiting for your advice. Thank you!
I'm using Intellij IDEA 14.1.4 to make an Android project after moving from Android Studio a while back. I made some libraries (through Android Studio) and would like to use them in Intellij.
However, it seems that Intellij only accepts .jar files through the libs folder, and Android Studio only creates .aar files.
In Android Studio, one has the option (when creating a new module) to import an existing .jar/.aar package to be put into a new module. This option doesn't seem to be in intellij. This user seems to think that Intellij supports that, but those instructions allow me to create a brand new Gradle module. What I want to do is use an existing .aar file.
What should I go about doing? Should I move back to Studio for this project, or is there a way for me to use these .aar files?
P.S. Intellij can't process raw aars, period. I tried adding this to my gradle files, but got an error:
compile fileTree(dir: 'libs', include: ['*.aar'])
Edit
Here's my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
flatDir() {
dirs 'libs'
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ':mylib#aar'
compile 'com.android.support:appcompat-v7:22.2.0'
}
So I saw this option in Intellj called "Associate file..." and associated the aar with an archive. Upon recompile I got this error
Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: mylib.aar
I guess it's only jars for Intellij. Back to Android Studio, I suppose :)
Well first of all you can create .jar files with Android Studio as well, see this but .aars are awesome and enable you to do more then what you could with a jar
I have not used Intellij IDEA but I assume you have a gradle.build file in your project? If the name of your aar file is
my_lib_1.0.0.aar
and its under the libs directory then try the following in your gradle.build file:
compile(name:'my_lib_1.0.0', ext:'aar')
This question is a sequel to this one.
In an existing Eclipse solution I have a library project which is used as a Android Dependency in the main app project. That means that if I edit this library, and compile, the main project is updated with the latest from that library.
I'm trying to do the same in Android Studio. That means not importing a library, but using it as a reference or dependency in the app project. I've been trying for two days now with no luck. Help is HIGHLY appreciated.
build.gradle (of the app project - there is nothing interesting her as I didn't change it much)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
You can try this steps:
Download library
File/import module
Select your library and rename :LibraryName
Go to build.gradle and write.
build.gradle
dependencies {
......
compile project(':LibraryName')
.....
}
Then if you import module you can edit library and proyect its updated
Say you have 2 projects, 1 application and 1 library project, you want to push all your external dependencies to your library project, so your application project only depends on the library project:
settings.gradle
include ':app'
include ':library'
app/build.gradle
apply plugin: 'com.android.application'
dependencies {
compile project(':library')
}
library/build.gradle
apply plugin: 'android-library'
dependencies {
compile 'external-dependencies-1'
compile 'external-dependencies-2'
...
}