我正在尝试使用Gradle构建我的第一个项目,我认为我的gradle文件和设置是正确的。
我只使用一个模块和支持V4 + AppCompatBar库。
项目 - build.gradle
allprojects {
repositories {
mavenCentral()
}
}
项目 - settings.gradle
include ':AssignmentTempos21'
主要模块 - 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.+"
}
带-i标志的控制台输出:
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
提前谢谢!!
答案 0 :(得分:94)
彼得说,他们不会在Maven Central
从Android SDK Manager下载'Android Support Repository',支持库的Maven repo将下载到您的Android SDK目录(参见'extras'文件夹)
要将库部署到本地.m2存储库,您可以使用maven-android-sdk-deployer
2017编辑:
您现在可以参考Google在线M2回购
repositories {
google()
jcenter()
}
答案 1 :(得分:50)
转到您安装Android Studio的任何地方(对我来说,它位于C:\Users\username\AppData\Local\Android\android-studio\
下)并打开sdk\tools
,然后运行android.bat
。从这里,更新并下载任何缺少的构建工具,并确保更新Extras下的Android支持存储库和Android支持库。 SDK Manager完成后重新启动Android Studio。
似乎Android Studio完全忽略了任何已安装的Android SDK文件并保留了自己的副本。运行更新后,使用compile com.android.support:appcompat-v7:18.0.+
答案 2 :(得分:27)
如果您在无头CI上运行并通过命令行安装Android SDK,请确保在--filter
参数中包含m2repository包:
android update sdk --no-ui --filter platform-tools,build-tools-19.0.1,android-19,extra-android-support,extra-android-m2repository,extra-google-m2repository
<强>更新强>
自Android SDK Manager rev。 22.6.4这不再起作用了。试试这个:
android list sdk --all
您将获得所有可用SDK包的列表。从上面的第一个命令(“Google Repository”和您可能缺少的其他命令)中查找组件的数值。
使用其数值安装包:
android update sdk --no-ui --all --filter <num>
更新#2(2017年9月)
使用今年早些时候发布的“新”Android SDK工具,android
命令现已弃用,类似的功能已移至名为sdkmanager
的新工具中:
列出已安装的组件:
sdkmanager --list
更新已安装的组件:
sdkmanager --update
安装新组件(例如构建工具版本26.0.0
):
sdkmanager 'build-tools;26.0.0'
答案 3 :(得分:5)
Maven Central(see this)中不存在这些依赖项。
答案 4 :(得分:2)
compileSdkVersion 17
targetSdkVersion 17
将编译版本从18更改为17
compile "com.android.support:support-v4:17.0.+"
compile "com.android.support:appcompat-v7:17.0.+"
答案 5 :(得分:2)
除了卡西姆的回答:
彼得说,他们不会在Maven Central
使用maven-android-sdk-deployer将库部署到您的 本地存储库
或者从Android SDK Manager下载Android支持存储库 (在Extras中)将下载支持库的M2 repo 到您的Android SDK目录
我还必须在Android SDK Manager中更新“支持库的本地Maven存储库”。
答案 6 :(得分:1)
回显@friederbluemle,如果您安装了Android SDK工具,也可以从命令行启动SDK管理器:
$ android
然后在弹出的UI中,选择需要安装的工具/存储库 - 在您的情况下,支持库存储库
答案 7 :(得分:1)
在app的build.gradle文件中编写以下语句。
com.android.support:appcompat-v7:18.0。+
就是这样
答案 8 :(得分:1)
我在Gradle Build标签中的Android Studio 2.1.1中收到此消息。我从SDK Manager安装了很多文件,但没有帮助。
我需要点击下一个标签&#34; Gradle Sync&#34;。有一个链接&#34;安装存储库和同步项目&#34;它安装了&#34; Android支持存储库&#34;。
答案 9 :(得分:1)
答案 10 :(得分:0)
将此添加到您的gradle中:
allprojects {
buildscript {
repositories {
maven {
url "https://dl.bintray.com/android/android-tools"
}
}
}
...
}