I am new to gradle and was wondering if I am doing something wrong or not when i try to load dependencies from the main Maven repo
this is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.github.clans:fab:1.6.2'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
and the error i get is
Error:(15, 17) Failed to resolve: com.facebook.android:facebook-android-sdk:4.7.0
Error:(14, 17) Failed to resolve: com.github.clans:fab:1.6.2
What is going on? Why am i seeing those errors? This text here is only so that stackoverflow stop complaining.
UPDATE:
This is gradle-wrapper.settings:
#Tue Nov 17 20:36:30 GMT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
Those are my dependencies in Android Studio. It even found it through the search ....
It seems, that you've forget to add the repository to your project. According to your build.script, you've added repo just in your buildscript. Just add repositories into the build.script root, before declaring dependencies, as:
repositories {
mavenCentral()
}
dependencies {...
Try with this:
apply plugin: 'com.android.application'
allprojects {
repositories {
jcenter()
mavenCentral()
}
dependencies { classpath 'com.android.tools.build:gradle:1.5.0' }
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.github.clans:fab:1.6.2'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
Or try:
Gradle settings -> Then uncheck Offline work
Related
I'm just installed the library Fabric for Crash monitoring, but now, I'm trying to add a library to rate your app (compile 'com.androidsx:rate-me:4.0.0') but now gradle stops showing that it failed to resolve the library.
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'io.fabric'
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.3.2#aar') {
transitive = true;
}
compile 'com.android.support:support-v4:22.1.1'
compile files('libs/library-1.0.6.jar')
compile files('libs/gcm.jar')
compile files('libs/acra-4.6.1.jar')
compile files('libs/acra-4.6.1-sources.jar')
compile files('libs/acra-4.6.1-javadoc.jar')
compile files('libs/TestFlightLib.jar')
compile files('libs/crouton-1.8.4.jar')
compile project(':LVL')
compile files('libs/bugsense-3.5.jar')
compile 'com.androidsx:rate-me:4.0.0'
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
The output:
What is the problem?
Solved:
jcenter() was missing inside repositories section.
Thanks.
For some unknown reason Gradle is refusing to download every dependancy that I put in my gradle.build file. I'm trying to get the 'me.dm7.barcodescanner:zbar:1.7' dependancy but every time I try to sync my gradle it just gives me the following error:
Error:(6, 13) Failed to resolve: me.dm7.barcodescanner:zbar:1.7
It's not just the zbar library either, it's every library this isn't a com.android library. I'm not in offline mode so that can't be it either. Is there something wrong in my .build file?
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':MetaioSDK')
compile 'com.android.support:support-v4:22.0.0'
compile 'me.dm7.barcodescanner:zbar:1.7'
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['../../templatesContent_crossplatform']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
Alright, managed to fix it. Added this inside the dependencies block:
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'me.dm7.barcodescanner:zbar:1.7'
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Put repository block independently from from other blocks
I have been using Android Studios from eclipe becuse Multidex 65000 compile Error!!!!
i did sync project gradle in android studio from eclipse project
i have problem compile Error in android studio
Error:Execution failed for task
':packageAllDevDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/multidex/MultiDex$V14.class
--build.gradle--
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android
{
compileSdkVersion 18
buildToolsVersion "20.0.0"
defaultConfig{
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
productFlavors {
dev {
minSdkVersion 18
}
prod {
minSdkVersion 18
}
}
}
why problem occurring
i want this problem solve
help me error sovle please
Recently I migrated my project to Android Studio. The project references a library project without copying it (See this answer).
I noticed that the apk generated from Android Studio is larger than the one generated from Eclipse (almost twice larger). When I unrar the two apk files I see that in the apk from Android Studio there is one more folder "main" and it contains "res" folder and AndroidManifest.xml.
The problem is that there is "res" folder (/res) in apk's main directory which contains the same resources (/main/res).
I think that the next gradle file causes the problem but without it the project can not be built.
build.gradle for my library module - my_android_project_lib module
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
// I think this duplicates the resources
sourceSets {
main {
manifest.srcFile 'my_android_project_lib/src/main/AndroidManifest.xml'
java.srcDirs = ['my_android_project_lib/src']
resources.srcDirs = ['my_android_project_lib/src']
aidl.srcDirs = ['my_android_project_lib/src']
renderscript.srcDirs = ['my_android_project_lib/src']
res.srcDirs = ['my_android_project_lib/src/main/res', 'slidingMenuLib/src/main/res']
assets.srcDirs = ['my_android_project_lib/src/main/assets']
}
}
}
dependencies {
compile project(':slidingMenuLib')
compile fileTree(dir: 'my_android_project_lib/libs', include: ['*.jar'])
compile fileTree(dir: 'slidingMenuLib/libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:1.7.1'
}
settings.gradle
include ':my_android_app'
include ':my_android_project_lib'
include ':slidingMenuLib'
project(':my_android_project_lib').projectDir = new File(settingsDir, '../my_android_project_lib')
build.gradle for my_android_app module
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my.android.app"
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(path: ':my_android_project_lib')
}
build.gradle for my_android_app project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Do you know how to fix the problem? I'm missing something important.
I found the problem. When I removed the following line from my build.gradle of my_android_project_lib module, application's size changed back to normal.
resources.srcDirs = ['anyoption_android_v2_lib/src']
The final build.gradle for my_android_project_lib module is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
// The problem is here.
sourceSets {
main {
manifest.srcFile 'my_android_project_lib/src/main/AndroidManifest.xml'
java.srcDirs = ['my_android_project_lib/src']
res.srcDirs = ['my_android_project_lib/src/main/res']
// Removed
// resources.srcDirs = ['my_android_project_lib/src'] - MAIN PROBLEM
// aidl.srcDirs = ['my_android_project_lib/src']
// renderscript.srcDirs = ['my_android_project_lib/src']
// res.srcDirs = ['my_android_project_lib/src/main/res', 'slidingMenuLib/src/main/res']
// assets.srcDirs = ['my_android_project_lib/src/main/assets']
}
}
}
dependencies {
compile project(':slidingMenuLib')
compile fileTree(dir: 'my_android_project_lib/libs', include: ['*.jar'])
compile fileTree(dir: 'slidingMenuLib/libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:1.7.1'
}
on commenting
resources.srcDirs = ['src']
in build.gradle file, worked for me.
The SourceSets in build.gradle file looks like this,
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
// resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
I've been at this for a couple of days trying to get the library structure correct within Android Studio. I would have just continued with Eclipse, but performance wise, it's been really bad for me lately. Please, any guidance would be greatly appreciated as all solutions found have not worked and the documentation has lead me nowhere.
All manifests have an empty application tag except for the main TestProject.
Edit* Prior to including SlidingMenu, I did have ActionBarSherlock working without issues and building, etc.
The Error
Gradle: Execution failed for task ':libraries:SlidingMenu:processReleaseManifest'.
> Manifest merging failed. See console for more info.
Build.Gradle (SlidingMenu)
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project(':libraries:actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Build.Gradle (ActionBarSherlock)
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Build.Gradle (Test Project)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project(':libraries:actionbarsherlock')
compile project(':libraries:SlidingMenu')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
settings.gradle (Test Project)
include ':TestProject',':libraries:actionbarsherlock',':libraries:SlidingMenu'
For me the problem was with 'missing <application/> tag' in slidingmenu library.
After adding empty <application/> tag to manifest errors disappeared.
Maybe this will help somebody.
See thread here: https://groups.google.com/forum/#!topic/adt-dev/PIah7eYXiNs
Unfortunately, this could be happening for a lot of reasons. I'd suggest running gradle build -info from the command line to see if it gives you more information.
A common merge failure I've run into is when the minSdkVersions are conflicting. I see that your test project minSdkVersion is 7, are the minimum levels declared in the ActionBarSherlock and SlidingMenu manifests 7 or less?
I already solve it. I share my configuration. Maybe this can help you.
Project:
+ TestProject
|-- libraries
|-- ActionBarSherlock
|-- actionbarsherlock
|-- actionbarsherlock-fest
|-- actionbarsherlock-i18n
|-- actionbarsherlock-samples
|-- SlidingMenu
|-- art
|-- example
|-- library
|-- library-maps-support
|-- TestProject
setting.gradle
include ':TestProject', ':libraries:SlidingMenu:library', ':libraries:ActionBarSherlock:actionbarsherlock'
build.gradle (Test Project)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile project(':libraries:ActionBarSherlock:actionbarsherlock')
compile project(':libraries:SlidingMenu:library')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
}
build.gradle (actionbarsherlock lib)
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
build.gradle (slidingmenu lib)
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':libraries:ActionBarSherlock:actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}