1

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

1 回答 1

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 版本。

于 2013-11-05T14:06:51.663 回答