Gradle Build Android Project “Could not resolve al

2019-01-21 07:37发布

I'm trying to build my first project with Gradle and I think my gradle files and settings are correct.

I'm using only one module and Support V4 + AppCompatBar libraries.

Project - build.gradle

allprojects {
    repositories {
        mavenCentral()
    }
}

Project - settings.gradle

include ':AssignmentTempos21'

Main module - build.gradle

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }
}

dependencies {
    compile "com.android.support:support-v4:18.0.+"
    compile "com.android.support:appcompat-v7:18.0.+"
}

Console output with -i flag:

MacBook-Air-de-Cesar-2:AssignmentTempos21 menor$ ./gradlew -i clean assemble
Starting Build
Settings evaluated using settings file '/Users/menor/workspace_android/AssignmentTempos21/settings.gradle'.
Projects loaded. Root project using build file '/Users/menor/workspace_android/AssignmentTempos21/build.gradle'.
Included projects: [root project 'AssignmentTempos21', project ':AssignmentTempos21']
Evaluating root project 'AssignmentTempos21' using build file '/Users/menor/workspace_android/AssignmentTempos21/build.gradle'.
Compiling build file '/Users/menor/workspace_android/AssignmentTempos21/build.gradle' using BuildScriptClasspathScriptTransformer.
Compiling build file '/Users/menor/workspace_android/AssignmentTempos21/build.gradle' using BuildScriptTransformer.
Evaluating project ':AssignmentTempos21' using build file '/Users/menor/workspace_android/AssignmentTempos21/AssignmentTempos21/build.gradle'.
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/support-v4/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml]
Resource missing. [HTTP GET: http://repo1.maven.org/maven2/com/android/support/appcompat-v7/]

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':AssignmentTempos21'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':AssignmentTempos21:_DebugCompile'.
      > Could not find any version that matches com.android.support:support-v4:18.0.+.
        Required by:
            AssignmentTempos21:AssignmentTempos21:unspecified
      > Could not find any version that matches com.android.support:appcompat-v7:18.0.+.
        Required by:
            AssignmentTempos21:AssignmentTempos21:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 40.787 secs

Thank you in advance!!

12条回答
Juvenile、少年°
2楼-- · 2019-01-21 07:43
compileSdkVersion 17
targetSdkVersion 17

change the compile version from 18 to 17

compile "com.android.support:support-v4:17.0.+"
compile "com.android.support:appcompat-v7:17.0.+"
查看更多
闹够了就滚
3楼-- · 2019-01-21 07:43

I had this message in Android Studio 2.1.1 in the Gradle Build tab. I installed a lot of files from the SDK Manager but it did not help.

I needed to click the next tab "Gradle Sync". There was a link "Install Repository and sync project" which installed the "Android Support Repository".

查看更多
\"骚年 ilove
4楼-- · 2019-01-21 07:44

Add this to your gradle:

allprojects {
    buildscript {
        repositories {
            maven {
                url "https://dl.bintray.com/android/android-tools"
            }
        }
    }
...
}
查看更多
等我变得足够好
5楼-- · 2019-01-21 07:46

As Peter says, they won't be in Maven Central

from the Android SDK Manager download the 'Android Support Repository' and a Maven repo of the support libraries will be downloaded to your Android SDK directory (see 'extras' folder)

to deploy the libraries to your local .m2 repository you can use maven-android-sdk-deployer

2017 edit:

you can now reference the Google online M2 repo

repositories {
google()
jcenter()
}
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-21 07:48
  1. Install android sdk manager
  2. check if building tools installed. install api 23.
  3. from the Android SDK Manager download the 'Android Support Repository'
  4. remove cordova-plugin-android-support-v4
  5. build
查看更多
狗以群分
7楼-- · 2019-01-21 07:50

to echo @friederbluemle, you can also just launch the SDK manager from the command line if you have the Android SDK tools installed:

$ android

and then in the UI that pops up, select the tools/repositories that need to be installed -- in your case the support library repo

查看更多
登录 后发表回答