我正在尝试使用 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