I'm currently downloaded newest android studio 0.3.2. I've been trying to add libraries for almost 5 hours, and nothing.
I've pressed F4 in the 'Module' where the libraries should go, added the libraries, also in the project structure added the dependencies, and also in build.gradle of the 'Module'. The errors in the IDE stop appearing, but when It 'compiles' it. It keeps telling me, that com.google.gson and other libraries don't exist.
How can I fix It? Or should I use Android studio?. Thank you very much.
EDIT
This is the build.gradle file, of the main project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
And this is the Gradle file o f the 'Module' that gives problems:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src']
main.resources.srcDirs = ['src']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
Here is an example for the Google Analytics library and the Gson library:
dependencies {
...
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/libGoogleAnalyticsServices.jar')
}
Related
I have a Android app project that depends on a vanilla Java project (':Common'). ':Common' depends on Guava which is located in the Java project's 'lib' directory. The java code in the android project references Guava classes (e.g. the 'Lists' class) as well as classes defined within ':Common'. The compilation of the android project fails due to not being able to find the 'Lists' class but is able to find the classes defined within ':Common' itself. I know this is a configuration that would normally work in a pure Java scenario, but I can't figure out why it fails in this Android case.
NOTE: Adding 'compile fileTree(dir: '../Common/lib', include: ['*.jar'])' to the dependencies of the Android project fixes the compilation error, but obviously this is suboptimal (you shouldn't have to define dependencies in two places like that in gradle).
The build.gradle file for my android project looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {(omitted)}
sourceSets {
main.manifest.srcFile 'AndroidManifest.xml'
main.java.srcDirs = ['src']
main.resources.srcDirs = ['resources']
main.res.srcDirs = ['res']
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile (project(':Common'))
}
The build.gradle file for my java library project (':Common') looks like:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src']
}
dependencies {
compile (fileTree(dir: 'lib', includes: ['*.jar']))
}
A very easy way to solve this problem is to declare guava as a remote dependency of the Common project and have Gradle resolve it at build time. Remote dependencies are transitive and your application would get it by virtue of depending on Common.
Try adding these lines to the build.gradle of the Common project:
dependencies {
compile 'com.google.guava:guava:18.0'
}
Then configure a base repository such as Maven Central:
repositories {
mavenCentral()
}
and remove the guava jar file from the lib/ folder.
I found an open source project I wanted to work on but I'm having trouble setting up the initial configuration. The project seems to have been written in Eclipse and I'm trying to get it to work with Android Studio. After being through a number of errors, I'm finally stuck on the following error seen in the configuration menu before I run.
AndroidManifest.XML doesn't exist or has the incorrect root tag
I found a number of answers that suggest like this that suggest I use the sync project with Gradle command but my project wasn't setup with Gradle because I'm building on someone else's project. This is my first time using Android Studio so my following attempt to fix this might not be great. I decided to try to make the project a Gradle project by adding my own build.gradle and settings.gradle files. My layout looks like this:
top level:
inside java folder:
I tried to copy working example of the build and settings Gradle files. My settings.gradle contains the following:
include ':'
My top level build.gradle contains:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//compile project(":")
}
}
allprojects {
repositories {
mavenCentral()
}
}
My java level build.gradle contains:
apply plugin: 'android'
android {
compileSdkVersion 20
buildToolsVersion "17.0.0"
defaultConfig {
applicationId "org.pocketworkstation.pckeyboard"
minSdkVersion 8
targetSdkVersion 19
versionCode 1037
versionName "v1.37"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
jni.srcDirs = ['jni']
}
androidTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And because I think it might be important, my project structure modules:
Trying to synchronize at the moment doesn't generate any word so I assume it's okay but that's a big assumption. Any ideas what I have to change?
Android Studio doesn't consider your project to be a Gradle-based project; you can tell this because a number of the entries you're seeing in the Project Structure dialog don't show up for Gradle-based projects (i.e. the Project, Libraries, Facets, and Artifacts) entries. Close your project and re-import it as a Gradle-based project and you should be okay.
I first added the android support library and tested that I could use it. However when I add Android Better Pickers in this maven repository I get the following error:
Gradle 'bumble' project refresh failed: Could not find
com.google.android:support-v4:18. Required by: myapp:app:unspecified
com.doomonafireball.betterpickers:library:1.4.2
This is how I set up my dependencies in the build.gradle located in MyProject -> app.
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.doomonafireball.betterpickers:library:1.4.2'
}
Android Better Pickers has the following in it's build.gradle and is packaged as an aar.
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.nineoldandroids:library:2.4.0'
}
Anyone know of a solution?
EDIT
Android better pickers now has gradle support since v 1.5! Now it is really easy adding it as a library, just follow there guide and don't forget to do a clean AND gradle sync after you change your build.gradle. Parts of the answers to this question still applies for none gradle projects I however.
First Make sure your are pointing to right sdk in File >Project Structure >Android SDK
In order to use Support Jar you have to install Android Support Repository from SDK Manager. SDK manager icon is available in Android Studio tool bar.
Things you should know for knowledge :
1.There is no need to add any dependency in your main module, if that is already added in any one of your library module already. So remove support dependency from your main module.
Make it something like this :
dependencies {
compile 'com.doomonafireball.betterpickers:library:1.4.2'
}
2.There is some issue going on in dependency management in android studio (0.4.2) which is fixed for Android Studio (0.4.3) but till the release check this as well For any dependency related issues.
Import Google Play Services library in Android Studio
EDIT :
I have checked the github repository there is no gradle dependency for date picker.
So do the following
Download Repository from github
Copy the library directory inside root of your project or make a directory and keep all your libraries inside that.The below configuration is for direct in root and I have renamed "library "to datepickerlibrary
Modify the build.gradle comes with library
build.gradle inside data picker library module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion '19.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
apply plugin: 'maven'
apply plugin: 'signing'
version = "1.4.0"
isReleaseVersion = !version.endsWith("SNAPSHOT")
group = "com.doomonafireball.betterpickers"
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.nineoldandroids:library:2.4.0'
}
Dependency in your main module's build.gradle should be like :
dependencies {
compile project(':datepickerlibrary') //if it is inside some sub directory you can give path like ':libraries:datepickerlibrary' depends on you
}
Add this line inside settings.gradle which is located in root of your Project directory:
include ':datepickerlibrary'
After these all checks, Do sync your project with gradle.
It worked for me, let me know if any issue comes.
ORIGINAL ASKER'S NOTES
I ended up doing something similar to the above and it worked great! What I did as a summary:
Downloaded and manually added the library as a dependency in Android Studio
Removed the following from the library's build.gradle (got a sonytype class not found exception or similar)
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: sonatypeRepo) {
authentication(userName: sonatypeUsername,
password: sonatypePassword)
}
Updated the library's SDK version to match the one I had installed.
I'm using Android Studio + gradle on MyProject + Facebook api as a library. See below settings.
I've tried removing all references of support-v4 (either r7 or 18.0.0) and replace them with support-v13, but the message with v4 was still present. I've also noticed that support-v4-r7 appears in External libraries, even though it's not referenced at all, anywhere. Would that be the problem ?
MyProject build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "https://raw.github.com/ark/ark/master/releases/"
}
}
dependencies {
compile 'com.andreabaccega:android-form-edittext:1.0.3'
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile 'com.google.android.gms:play-services:3.1.36'
compile files('libs/imageloader-core-1.5.8.jar')
compile project(':libs:Facebook')
}
android {
compileSdkVersion 17
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'libs/Facebook/src', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
resources.srcDirs = ['build', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
MyProject settings.gradle:
include ':MyProject'
include ':libs:Facebook'
Facebook build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion '18.1'
defaultConfig {
minSdkVersion 8
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'build/source/r/debug', 'build/source/buildConfig/debug']
resources.srcDirs = ['build/source/r/debug', 'build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
Edit: I've tried adding the libs that I use in this project, in another project, one by one, to see what fails. Apparently these 2 are the culprits. If I include any or both of them, I get the above error.
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
Any ideas on how to manage this ?
Edit2: Apparently another project presents the same issue. See build.gradle dependencies below. StickyListHeaders project doesn't contain anymore dependencies. So I presume it's because of ActionBarSherlock ?
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile project(':Project Base:libs:StickyListHeaders')
}
Apparently there were 2 reasons for this issue.
1) PagerSlidingTabStrip library depends on a local support lib v4 jar. Remove the dependency and add the project as a library project in your app and inside it add the maven dependency for support v4. So it should look exactly like the Facebook library project from above.
2) RoboSpice library depends on LRUCache from support lib v4 (https://github.com/octo-online/robospice/issues/195). Just exclude it from your main build.gradle file and you should be good to go.
compile ('com.octo.android.robospice:robospice-spring-android:1.4.7')
{
exclude module: 'support-v4'
}
Hopefully this will help somebody and not spend an entire week with this problem like I did. Oh, and trillion of thanks to #Snicolas. Couldn't have solved it without his help.
Edit: As of RoboSpice v1.4.8, there is no more local support lib dependency, so this issue is fixed.
For anyone who happens to hit this error while using Visual Studio with Xamarin, like I did;
I solved it by simply removing the reference to "Xamarin.Android.Support.v4" from the References folder within the project, then cleaned and built project as normal.
When this is for Xamarin.Android, this error occurs for version mismatching between depended packages. You've got to remove this Xamarin.Android.Support.v4 package from the project along with other mismatching packages. (What does mismatching means here is, if your target Android version is Android 6, all packages listed in the packages.config file should have targetFramework="monoandroid60" packages. If any package won't abide this, it's a mismatching version). If you have messed with versions, then removing the reference and cleaning stuff alone won't work. You've got to remove all the mismatching packages from the Nuget Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages for Solution...). Note that when you're to remove these packages, you'll also need to remove the depended packages. No harm go ahead and remove them all and you can re-install them with the correct version.
Once you've removed the package along with the dependent packages, try building the project. After a successful build, re-install the packages from the Nuget Package Manager with the correct version. (Package versions are listed according to the API levels, Ex: Android 6 which is API 23, would support packages of version 23.x.x)
Cleanup the project and build it, hopefully it'll succeed building!
Hope this'll help cleanup the mess!
Run "gradle androidDependencies" and check your dependencie tree. Add an exclude for the modules that are overlapped.
For example i had to do the following:
dependencies {
compile 'com.google.android:support-v4:r7'
compile project(':libraries:actionbarsherlock')
compile ('com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+') {
// Need to specifically exclude this as it is specified in our own project
exclude module: 'actionbarsherlock'
exclude module: 'support-v4'
}
}
The page slider library also have support library dependency. Thus you are getting this error. In case of maven all you need to do is change your main project pom file dependency entry of the support library to scope as provided.
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>13</version>
<scope>provided</scope>
</dependency>
In case of gradle i think you need to change the dependency configuration to match maven provided scope
Please refer the following link for more details Convert Maven to Gradle
I just got this same issue. I simply updated all Xamarin.Android.Support… nuget packages to the same version.
Note: this app was older so I did not go to the Latest stable version as there were other dependencies that would have needed to be updated. I simply moved them all to the highest common version.
Good luck!
Tom
Remove all old reference .dlls and relevant to that and add again from NuGet.
I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()