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')
Related
Here i got a problem, I have already installed build tool in revision 24.0.1, here is the screen snapshot from my terminal:
And in fact I think I wrote it well in the build.gradle filebuildToolsVersion "24.0.1", but while sync the project it still appear such error:
fail to find build tool revision 24.0.1 install such build tools
Another question is about the file place order in android studio. Below is the imported project hierarchy and the manifest file is under the main folder and i can not find any usage file under android perspective.
Such a project hierarchy I have never seen, maybe there is somebody who could demonstrate such answer to me. Thank you.
Update: Here is the build.gradle file picture
You are doing it in the wrong way. There are two types of build.gradle files. The first one is for your project and the second type for module which can be more than one. In your case you are mixing both.
The project's build.gradle should like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the module build.gradle should look something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.something"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
}
Regarding your second question, the hierarchy you see is called Project view.
By default, Android Studio displays your project files in the Android view. This view does not reflect the actual file hierarchy on disk, but is organized by modules and file types to simplify navigation between key source files of your project, hiding certain files or directories that are not commonly used.
(...) To see the actual file structure of the project including all files hidden from the Android view, select Project from the dropdown at the top of the Project window.
Source: https://developer.android.com/studio/projects/index.html
I'd like to share my source code among different projects through aar. Current version of Android studio is able to generate aar files automatically for library module. But I have a few issues:
How to output aar files to specific folder?
Currently the output is in build/outputs/aar folder. Can I move the files automatically once the compilation has been finished.
The dependencies in library module is not inherited by app module. For example:
My library module (build.gradle):
apply plugin: 'com.android.library'
......
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.2.4'
}
My app module:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
flatDir {
dirs 'myaarfolder'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.company.appid"
minSdkVersion 8
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'
compile(name:'mylib-release', ext:'aar')
}
I got an error something like:
Error:(3, 35) Error: Package com.google.gson.annotations not exist
I have to add compile 'com.google.code.gson:gson:2.2.4' in the dependency of my app module (build.gradle)
Any idea? Thanks
AAR files don't have their dependencies baked into them, so if you're including a bare AAR like this, you'll need to manually add dependencies in the parent module. To do what you want you'd need to package the AAR into a Maven artifact and specify its dependencies in the POM. A quick search of Google reveals this link, which looks like it's for an older version of the Android Gradle plugin, but it might get you going, or you can do your own searching for a better resource:
http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven
If you want to manipulate of your output files, you can take inspiration from this question, which renames outputs:
Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl
Essentially it involves a block of build script that looks like this:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, /* calculate new path here */)
}
}
I'm trying to set up Double Espresso, but that's probably not relevant here. What I'm trying to do is to set up a project in Android Studio using Gradle.
I'm very new to Gradle and build tools in general, though I've successfully used Maven before. Despite an hour of searching I can't find an answer to a very simple question.
In Jake Wharton's instructions it says
No more fumbling with local jars or dependency conflicts. Pull it in with one line:
androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
Pull in where? Where do I put/execute that command to import the project? In the command prompt? Do I put it in one of the scripts?
Thanks for any help.
You have a build.gradle file inside your app folder. In that file you can configure your project, "dependencies" and other options. It's very similar to maven. You have another build.gradle file in your root folder from your project. This conf file is more general and call the other build.gradle file.
e.g I have in one of my projects
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.acostela.example"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.+'
compile "com.android.support:gridlayout-v7:18.0.+"
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'commons-net:commons-net:3.3'
compile 'net.sf.opencsv:opencsv:2.3'
}
Dependencies here are similar to maven and the use in that tool of "/".
Gradle take libs from repositories in the same way of maven. In fact you can use the maven repository. You have a tab with the gradle sentence to download libraries.
http://mvnrepository.com/artifact/com.squareup.assertj/assertj-android/1.0.0
Hey guys I really got a problem I can't solve.
I'm developing an Android application which needs a library I wrote for myself (model.jar). I added it to Android Studio and everything was fine.
On some point it just didn't work anymore so I did everything I could do:
removed the not working library from my project
put the library to the projects /libs directory
added the libray via Project Structure -> File dependency -> model.jar
added the jar to the projects .gradle file to compile
Rebuild Project
Invalidate Caches and restart
deleted the projects .iml file and .idea folder and reimported the application
executed gradlew clean and gradlew assemble from command line
edit: I did also a Sync Project with Gradle Files
However none of these worked. It still cannot resolve the objects from the jar and I'm just stuck.
Since I am not allowed to post images directly I uploaded it into my dropbox
Note that I cannot expand the model.jar as the other libraries that do work.
The build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "de.rcsrcs.osiris"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/mina-core-2.0.9.jar')
compile files('libs/slf4j-api-1.7.7.jar')
compile files('libs/slf4j-log4j12-1.7.7.jar')
compile files('libs/slf4j-jdk14-1.7.7.jar')
compile files('libs/model.jar')
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
}
As said before, the mina libraries work fine.
Thanks for your help!
JAR files, being files, can get mangled accidentally from time to time. If your IDE sees the JAR (e.g., it shows up in the list of dependencies in Android Studio), but it does not see contents of the JAR, check to make sure that it is a clean copy of the JAR. Ideally, the IDE would be a bit more "in your face" about a broken JAR file...
I've imported a library in Android studio (0.5.3)
My settings.graddle looks like this:
include ':app', ':libs:Android-PullToRefresh-master'
And my build.graddle looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
project(':libs:Android-PullToRefresh-master');
}
The folder I've downloaded is placed in the libs folder directly under the app folder. Also the graddle syncs and building doesn't provide any error. Yet whenever I try to import import com.handmark.xxxxxx; I get the error cannot resolve symbol 'handmark'. I've chcecked to project structure and the app has the dependency in the list.
What is going wrong and how can I fix this?
I ran into the same issue here and asked the question on the "Android Developer Tools" Google+'s community. Alex Ruiz picked up the conversation and told me:
I'm able to reproduce this issue. Unfortunately, no updates yet. We
are currently fixing the "Project Structure" (the core
infrastructure,) and we will get to this, hopefully soon.
So they are aware of it but we still have to wait until they fix it.
In the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new lib.
I had the exact same problem as this, however the library file was an aar file, and it happened a long time after adding the library and developing with it for a while.
Building on the information Thomas provided; I found to fix this you should replace the file dependency with a maven dependency if possible. A good resource for finding and creating your Gradle dependency is Gradle, please.
That site returns the below dependency when searching for PullToRefresh
dependencies {
compile 'com.loopeer.android.thirdparty.pulltorefresh:Android-PullToRefresh:2.1.1'
}