我是Android开发人员的首发,我目前真的很难实现actionbarsherlock。我知道之前已经讨论过了,但我对依赖关系以及如何设置项目结构感到非常困惑。我试着遵循所有说明,但它没有成功。我一直对gradle有不同的问题。我正在使用Android Studio 0.2.0。
我当前的错误说:
>Gradle 'MyAppProject' project refresh failed:
>Could not fetch model of type 'IdeaProject' using Gradle distribution "http://services.gradle.org/distributions/gradle-1.6-bin.zip".
>Error: Gradle: A problem occurred configuring project ':MyApp'.
>Failed to notify project evaluation listener.
>A problem occurred configuring project ':Libraries:ActionBarSherlock'.
>Failed to notify project evaluation listener.
>Main Manifest missing from C:\Users\JJ2\AndroidStudioProjects\MyAppProject\Libraries\ActionBarSherlock\src\main\AndroidManifest.xml
我的项目构建如下:
-MyAppProject
|+.idea
|+gradle
|-Libraries
||-ActionBarSherlock
|||+gen
|||+libs
|||+res
|||-src
||||-android.support.v4.app
|||||-Watson
||||+com.actionbarsherlock
|||-ActionBarSherlock.iml
|||-AndroidManifest.xml
|||-build.gradle
|||-lint.xml
|||-pom.xml
|||-project.properties
|||-README.md
|-MyApp
||+build
||+libs
||-src
|||-main
||||-java
|||||+com.mywebsite.myapp
||||+res
||||-AndroidManifest.xml
||||-ic_launcher-web.png
||-build.gradle
||-MyApp.iml
|-build.gradle
|-gradlew
|-gradlew.bat
|-local.properties
|-settings.gradle
|-MyAppProject.iml
-External Libraries
|-<Android 4.2.2>
||+android.jar
||+annotations.jar
||+res
MyAppProject目录中build.gradle的内容:
task assemble{}
MyApp目录中的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android'
dependencies {
compile project(":Libraries:ActionBarSherlock")
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
}
Libraries \ ActionBarSherlock目录中的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
}
最后,我的项目结构如下:
模块
-ActionBarSherlock (Dependencies: Android 4.2.2, [v]android-support-v4)
-Android
-MyApp (Dependencies: Android 4.2.2, [ ]ActionBarSherlock)
-Android
-Android-Gradle
-MyAppProject (Dependencies: Android 4.2.2)
-Android-Gradle
库
None
全球图书馆
-android-support-v4 (Classes: ...\MyAppProject\MyApp\libs\android-support-v4.jar)
我希望有人可以注意到代码有什么问题,尽管自从新的Android Studio发布以来,很多人似乎都有未解决的问题。 提前谢谢!
答案 0 :(得分:3)
热门目录settings.gradle:
include ':MyApp', ':Libraries:ActionBarSherlock'
包括您可以输入项目的任何其他库
热门目录build.gradle: 它可以用任务汇编{}
Actionbar sherlock build.gradle
buildscript {
repositories {
mavenCentral()
}
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 7
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')
}
}
此外,设置了gradle版本的IN ALL .gradle文件: 将gradle版本替换为:
classpath 'com.android.tools.build:gradle:0.5.+'
Android Studio 2.x使用gradle 0.5.x,并且使用+
您将保持您的gradle最新(他们在2天之前更新它,我们经常更新!)
现在你的gradle设置没问题! 的注1:强> iml./idea文件中可能出现任何其他错误...您可以尝试在Studio的项目设置中更改它们,例如为每个模块(sherlock,MyApp)设置源文件,它们的库等等!
注2: 此外,如果您正在使用其他库,这需要比您的应用程序更高版本的SDK,您可能会收到错误,无解释!