在现有的 Android 项目中使用 Gradle [英] Using Gradle with an existing Android project

查看:27
本文介绍了在现有的 Android 项目中使用 Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的 Android 项目,其结构如下:

I have an existing Android project with the following structure:

- ProjectName
-- AndroidManifest.xml
-- local.properties
-- project.properties

-- assets
-- libs    (containing all jars)
-- modules (containing all library projects my project depends on)
-- res

-- src
---- com/namespace/projectname (all my classes including main activity are here)

除了 Android Studio IDE 默认提供的构建系统之外,我没有使用任何特定的构建系统来构建我的项目(尽管该项目最初是使用 IntelliJ CE 创建的.

I haven't been using any specific build system to build my project other than the one provided by default with the Android Studio IDE (though the project was originally created with IntelliJ CE.

我想将 Gradle 与 android 插件一起使用,并在我的构建过程中做一些工作.为了实现这一点,我尝试了多种配置,但每次都无法成功构建.

I would like to use Gradle with the android plugin and do some work on my build process. I have tried several configurations in order to achieve this and have failed to complete a successful build every time.

在这种情况下推荐的方法是什么?我应该改变我的项目结构吗?或者是否可以使用现有结构配置 gradle?

What's the recommended approach in this scenario? should I change my project structure? or is it possible to configure gradle using the existing structure?

任何帮助将不胜感激.

谢谢!

推荐答案

在这种情况下推荐的方法是什么?我应该改变我的项目结构?或者是否可以使用现有结构?

What's the recommended approach in this scenario? should I change my project structure? or is it possible to configure gradle using the existing structure?

完全可以使用您现有的结构来配置 gradle.

It's perfectly possible to configure gradle using your existing structure.

您需要为每个库项目添加一个 build.gradle.您还需要在项目根文件夹中添加一个 build.gradle 和一个 settings.gradle 文件.

You need to add a build.gradle to each library project. You also need to add a build.gradle and a settings.gradle files to the project root folder.

应该是这样的:

  ProjectName
    build.gradle     <<<<<<
    settings.gradle  <<<<<<
    AndroidManifest.xml
    local.properties
    project.properties
    assets
    res
    src
    libs    
    modules 
       module1
          build.gradle  <<<<<<
       module2
          build.gradle  <<<<<<
       module3
          build.gradle  <<<<<<

settings.gradle 中,您需要包含所有项目文件夹,如果您的主项目位于子文件夹中,则也应包含在内,实际情况并非如此.

In settings.gradle you need to include all projects folders, if your main project was in a sub-folder it should also be included, which is not in the case.

settings.gradle 应该是这样的:

settings.gradle should look like this:

include ':modules:module1', ':modules:module2', ':modules:module2'

主项目的build.gradle应该有:

build.gradle of the main project should have:

dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile project(':modules:module1') 
        compile project(':modules:module2') 
        compile project(':modules:module3') 
}

这篇关于在现有的 Android 项目中使用 Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆