我正在尝试使用Gradle构建我的Android Studio项目,并且要诚实,我不确定我在做什么!
以下是我的设置方式:
build.gradle(在我的Facebook模块中)
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
build.gradle(在我的主模块中)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'FriendProject\\libs', include: '*.jar')
compile project(':libraries:facebook')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
sourceSets {
main {
manifest.srcFile 'FriendProject\\src\\main\\AndroidManifest.xml'
java.srcDirs = ['FriendProject\\src']
resources.srcDirs = ['FriendProject\\src']
aidl.srcDirs = ['FriendProject\\src']
renderscript.srcDirs = ['FriendProject\\src']
res.srcDirs = ['FriendProject\\src\\main\\res', 'FriendProject\\src']
assets.srcDirs = ['FriendProject\\assets']
}
debug.setRoot('FriendProject\\build-types\\debug')
release.setRoot('FriendProject\\build-types\\release')
}
}
settings.gradle(在主模块中)
include ':libraries:facebook', ':FriendProject'
现在,在命令行中输入:
gradle packageDebug
我得到了一大堆错误,但都是这种格式:
symbol: variable id
location: class R
error: cannot find symbol
_layout = (RelativeLayout) findViewById(R.id.mainLayout);
^
如果有人可以提供帮助,我会很感激。我根本不熟悉这些,但如果您需要更多信息,我可以提供。感谢
(另外作为一个附带问题,如何让Gradle在Android Studio中工作?它说我需要迁移我的项目,但不知道该怎么做。再次感谢!)
* 编辑:*
如果需要,我的项目目录树在这里:
+---FriendProject
| +---build
| | \---manifests
| | \---debug
| +---libs
| +---resarwae
| | +---manifests
| | | \---debug
| | | \---gen
| | | \---com
| | | \---Marsh
| | | \---friendproject
| | \---source
| | +---buildConfig
| | \---r
| \---src
| \---main
| +---gen
| | \---com
| | \---Marsh
| | \---friendproject
| +---java
| | \---com
| | \---Marsh
| | \---friendproject
| | +---Activities
| | +---AdapterDetails
| | +---Adapters
| | +---Base
| | +---Fragments
| | +---Miscellaneous
| | +---Utilities
| | \---Views
| \---res
| +---drawable
| +---drawable-hdpi
| +---drawable-mdpi
| +---drawable-xhdpi
| +---drawable-xxhdpi
| +---layout
| +---menu
| +---values
| +---values-sw600dp
| +---values-sw720dp-land
| +---values-v11
| +---values-v14
| \---xml
+---gradle
| \---wrapper
+---libraries
| \---facebook
| +---gen
| | \---com
| | \---facebook
| | \---android
| +---libs
| +---res
| | +---drawable
| | +---drawable-hdpi
| | +---drawable-ldpi
| | +---drawable-mdpi
| | +---drawable-xhdpi
| | +---layout
| | +---values
| | +---values-es
| | +---values-hdpi
| | +---values-he
| | +---values-iw
| | +---values-ldpi
| | +---values-mdpi
| | \---values-xhdpi
| +---src
| | \---com
| | \---facebook
| | +---android
| | +---internal
| | +---model
| | \---widget
| +---TestApp
| | +---res
| | | +---drawable-hdpi
| | | +---drawable-ldpi
| | | +---drawable-mdpi
| | | +---layout
| | | \---values
| | \---src
| | \---com
| | \---facebook
| | \---sdk
| \---tests
| +---assets
| +---res
| | +---layout
| | \---values
| \---src
| \---com
| \---facebook
| +---internal
| +---model
| \---widget
答案 0 :(得分:0)
如果消息显示您的项目使用旧版本的Gradle,那么您应该将所有行classpath 'com.android.tools.build:gradle:0.4'
更改为classpath 'com.android.tools.build:gradle:0.6+'
或您要使用的任何版本并重建您的项目。
如果您想使用Android Studio正在使用的Gradle版本,则可以在项目目录中修改文件“gradle / wrapper / gradle-wrapper.properties”。它看起来应该是这样的(在Linux上):
#
#Thu Jul 18 15:45:25 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
并将distributionUrl更改为您要使用的版本。然后关闭您的项目并重新打开它,Android Studio应下载并使用新的gradle版本。