I'm trying to build my first project with Gradle and I think my gradle files and settings are correct.
我正在尝试用Gradle构建我的第一个项目,我认为我的Gradle文件和设置是正确的。
I'm using only one module and Support V4 + AppCompatBar libraries.
我只使用一个模块,支持V4 + AppCompatBar库。
Project - build.gradle
项目——build.gradle
allprojects {
repositories {
mavenCentral()
}
}
Project - settings.gradle
项目——settings.gradle
include ':AssignmentTempos21'
Main module - build.gradle
主要模块——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:
带有-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
Thank you in advance!!
提前谢谢你! !
11 个解决方案
#1
92
As Peter says, they won't be in Maven Central
正如彼得所说,他们不会在Maven中心
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)
从Android SDK管理器下载“Android支持存储库”,支持库的Maven repo将下载到您的Android SDK目录(参见“附加”文件夹)
to deploy the libraries to your local .m2 repository you can use maven-android-sdk-deployer
要将库部署到本地的.m2存储库,您可以使用maven-android-sdk-deployer。
2017 edit:
2017编辑:
you can now reference the Google online M2 repo
您现在可以参考谷歌在线M2 repo
repositories {
google()
jcenter()
}
#2
49
Go to wherever you installed Android Studio (for me it's under C:\Users\username\AppData\Local\Android\android-studio\
) and open sdk\tools
, then run android.bat
. From here, update and download any missing build-tools and make sure you update the Android Support Repository and Android Support Library under Extras. Restart Android Studio after the SDK Manager finishes.
去哪里你安装Android工作室(对我来说这是C:\Users\username\AppData\Local\Android\ android-studio \)和开放的sdk \工具,然后运行android.bat。从这里,更新和下载任何丢失的构建工具,并确保您在Extras之下更新Android Support Repository和Android Support Library。在SDK管理器完成后重新启动Android Studio。
It seems that Android Studio completely ignores any installed Android SDK files and keeps a copy of its own. After running an update, everything compiled successfully for me using compile com.android.support:appcompat-v7:18.0.+
似乎Android Studio完全忽略了Android SDK安装的任何文件,并保留了自己的副本。在运行更新之后,使用compile .android.support:appcompat-v7:18.0.+为我成功地编译
#3
26
If you are running on headless CI and are installing the Android SDK through command line, make sure to include the m2repository packages in the --filter
argument:
如果您正在使用无头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
Update
更新
As of Android SDK Manager rev. 22.6.4 this does not work anymore. Try this instead:
从Android SDK管理器rev. 22.6.4开始,这不再有效。试试这个:
android list sdk --all
You will get a list of all available SDK packages. Look up the numerical values of the components from the first command above ("Google Repository" and others you might be missing).
您将获得所有可用SDK包的列表。从上面的第一个命令(“谷歌存储库”和其他可能丢失的命令)查找组件的数值。
Install the packages using their numerical values:
使用它们的数值安装包:
android update sdk --no-ui --all --filter <num>
Update #2 (Sept 2017)
更新# 2(2017年9月)
With the "new" Android SDK tools that were released earlier this year, the android
command is now deprecated, and similar functionality has been moved to a new tool called sdkmanager
:
随着今年早些时候发布的“新的”Android SDK工具,Android命令现在被弃用,类似的功能也被转移到一个叫做sdkmanager的新工具:
List installed components:
安装组件列表:
sdkmanager --list
Update installed components:
更新已安装组件:
sdkmanager --update
Install a new component (e.g. build tools version 26.0.0
):
安装一个新的组件(例如,构建工具版本26.0.0):
sdkmanager 'build-tools;26.0.0'
#5
2
compileSdkVersion 17
targetSdkVersion 17
change the compile version from 18 to 17
将编译版本从18更改为17
compile "com.android.support:support-v4:17.0.+"
compile "com.android.support:appcompat-v7:17.0.+"
#6
2
In addition to Kassim's answer:
除了卡西姆的回答:
As Peter says, they won't be in Maven Central
正如彼得所说,他们不会在Maven中心
Either use maven-android-sdk-deployer to deploy the libraries to your local repository
可以使用maven-android-sdk-deployer将库部署到本地存储库
Or from Android SDK Manager download the Android Support Repository (in Extras) and an M2 repo of the support libraries will be downloaded to your Android SDK directory
或者从Android SDK管理器下载Android支持库(额外的),支持库的M2 repo将下载到Android SDK目录。
I also had to update the "Local Maven repository for Support Libraries" in Android SDK Manager.
我还必须更新Android SDK管理器中的“支持库的本地Maven存储库”。
#7
1
to echo @friederbluemle, you can also just launch the SDK manager from the command line if you have the Android SDK tools installed:
对于echo @friederbluemle,如果您安装了Android SDK工具,您还可以从命令行启动SDK管理器:
$ android
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
然后在弹出的UI中,选择需要安装的工具/存储库——在您的情况下,支持库repo。
#8
1
write following statement in your app's build.gradle file.
在应用程序的构建中编写以下语句。gradle文件。
com.android.support:appcompat-v7:18.0.+
com.android.support:appcompat-v7:18.0。+
That's it
就是这样
#9
1
Try to turn off your firewall, it works for me
. It seems that android studio wants to download some dependencies and our firewall prevents it from downloading it, just be aware that turning your firewall off may lower the security of your computer
. If you have more time you can manually allow your android studio to bypass your firewall, this way you can turn on your firewall while allowing android studio to download anything that it wants.
试着关掉你的防火墙,它对我有用。似乎android studio想要下载一些依赖项,我们的防火墙阻止它下载它,只是要注意关闭防火墙可能降低您的计算机的安全性。如果您有更多的时间,您可以手动允许您的android studio绕过您的防火墙,这样您可以打开您的防火墙,同时允许android studio下载它想要的任何东西。
#10
1
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.
我在Android Studio 2.1.1中有这个消息,在Gradle Build选项卡中。我安装了很多来自SDK管理器的文件,但是没有帮助。
I needed to click the next tab "Gradle Sync". There was a link "Install Repository and sync project" which installed the "Android Support Repository".
我需要点击下一个标签“等级同步”。有一个链接“安装存储库和同步项目”安装了“Android支持存储库”。
#11
1
- Install android sdk manager
- 安装android sdk管理器
- check if building tools installed. install api 23.
- 检查建筑工具是否安装。安装api 23。
- from the Android SDK Manager download the 'Android Support Repository'
- 从Android SDK管理器下载“Android支持存储库”
- remove cordova-plugin-android-support-v4
- 删除cordova-plugin-android-support-v4
- build
- 构建
#1
92
As Peter says, they won't be in Maven Central
正如彼得所说,他们不会在Maven中心
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)
从Android SDK管理器下载“Android支持存储库”,支持库的Maven repo将下载到您的Android SDK目录(参见“附加”文件夹)
to deploy the libraries to your local .m2 repository you can use maven-android-sdk-deployer
要将库部署到本地的.m2存储库,您可以使用maven-android-sdk-deployer。
2017 edit:
2017编辑:
you can now reference the Google online M2 repo
您现在可以参考谷歌在线M2 repo
repositories {
google()
jcenter()
}
#2
49
Go to wherever you installed Android Studio (for me it's under C:\Users\username\AppData\Local\Android\android-studio\
) and open sdk\tools
, then run android.bat
. From here, update and download any missing build-tools and make sure you update the Android Support Repository and Android Support Library under Extras. Restart Android Studio after the SDK Manager finishes.
去哪里你安装Android工作室(对我来说这是C:\Users\username\AppData\Local\Android\ android-studio \)和开放的sdk \工具,然后运行android.bat。从这里,更新和下载任何丢失的构建工具,并确保您在Extras之下更新Android Support Repository和Android Support Library。在SDK管理器完成后重新启动Android Studio。
It seems that Android Studio completely ignores any installed Android SDK files and keeps a copy of its own. After running an update, everything compiled successfully for me using compile com.android.support:appcompat-v7:18.0.+
似乎Android Studio完全忽略了Android SDK安装的任何文件,并保留了自己的副本。在运行更新之后,使用compile .android.support:appcompat-v7:18.0.+为我成功地编译
#3
26
If you are running on headless CI and are installing the Android SDK through command line, make sure to include the m2repository packages in the --filter
argument:
如果您正在使用无头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
Update
更新
As of Android SDK Manager rev. 22.6.4 this does not work anymore. Try this instead:
从Android SDK管理器rev. 22.6.4开始,这不再有效。试试这个:
android list sdk --all
You will get a list of all available SDK packages. Look up the numerical values of the components from the first command above ("Google Repository" and others you might be missing).
您将获得所有可用SDK包的列表。从上面的第一个命令(“谷歌存储库”和其他可能丢失的命令)查找组件的数值。
Install the packages using their numerical values:
使用它们的数值安装包:
android update sdk --no-ui --all --filter <num>
Update #2 (Sept 2017)
更新# 2(2017年9月)
With the "new" Android SDK tools that were released earlier this year, the android
command is now deprecated, and similar functionality has been moved to a new tool called sdkmanager
:
随着今年早些时候发布的“新的”Android SDK工具,Android命令现在被弃用,类似的功能也被转移到一个叫做sdkmanager的新工具:
List installed components:
安装组件列表:
sdkmanager --list
Update installed components:
更新已安装组件:
sdkmanager --update
Install a new component (e.g. build tools version 26.0.0
):
安装一个新的组件(例如,构建工具版本26.0.0):
sdkmanager 'build-tools;26.0.0'
#4
#5
2
compileSdkVersion 17
targetSdkVersion 17
change the compile version from 18 to 17
将编译版本从18更改为17
compile "com.android.support:support-v4:17.0.+"
compile "com.android.support:appcompat-v7:17.0.+"
#6
2
In addition to Kassim's answer:
除了卡西姆的回答:
As Peter says, they won't be in Maven Central
正如彼得所说,他们不会在Maven中心
Either use maven-android-sdk-deployer to deploy the libraries to your local repository
可以使用maven-android-sdk-deployer将库部署到本地存储库
Or from Android SDK Manager download the Android Support Repository (in Extras) and an M2 repo of the support libraries will be downloaded to your Android SDK directory
或者从Android SDK管理器下载Android支持库(额外的),支持库的M2 repo将下载到Android SDK目录。
I also had to update the "Local Maven repository for Support Libraries" in Android SDK Manager.
我还必须更新Android SDK管理器中的“支持库的本地Maven存储库”。
#7
1
to echo @friederbluemle, you can also just launch the SDK manager from the command line if you have the Android SDK tools installed:
对于echo @friederbluemle,如果您安装了Android SDK工具,您还可以从命令行启动SDK管理器:
$ android
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
然后在弹出的UI中,选择需要安装的工具/存储库——在您的情况下,支持库repo。
#8
1
write following statement in your app's build.gradle file.
在应用程序的构建中编写以下语句。gradle文件。
com.android.support:appcompat-v7:18.0.+
com.android.support:appcompat-v7:18.0。+
That's it
就是这样
#9
1
Try to turn off your firewall, it works for me
. It seems that android studio wants to download some dependencies and our firewall prevents it from downloading it, just be aware that turning your firewall off may lower the security of your computer
. If you have more time you can manually allow your android studio to bypass your firewall, this way you can turn on your firewall while allowing android studio to download anything that it wants.
试着关掉你的防火墙,它对我有用。似乎android studio想要下载一些依赖项,我们的防火墙阻止它下载它,只是要注意关闭防火墙可能降低您的计算机的安全性。如果您有更多的时间,您可以手动允许您的android studio绕过您的防火墙,这样您可以打开您的防火墙,同时允许android studio下载它想要的任何东西。
#10
1
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.
我在Android Studio 2.1.1中有这个消息,在Gradle Build选项卡中。我安装了很多来自SDK管理器的文件,但是没有帮助。
I needed to click the next tab "Gradle Sync". There was a link "Install Repository and sync project" which installed the "Android Support Repository".
我需要点击下一个标签“等级同步”。有一个链接“安装存储库和同步项目”安装了“Android支持存储库”。
#11
1
- Install android sdk manager
- 安装android sdk管理器
- check if building tools installed. install api 23.
- 检查建筑工具是否安装。安装api 23。
- from the Android SDK Manager download the 'Android Support Repository'
- 从Android SDK管理器下载“Android支持存储库”
- remove cordova-plugin-android-support-v4
- 删除cordova-plugin-android-support-v4
- build
- 构建