小编典典

Android Studio:如何创建在Jenkins上使用的build.gradle文件?

jenkins

我是新手,想要弄清楚如何在我们的Jenkins构建机器上进行设置。我们的应用程序可以在Android
Studio内完美构建,但从未生成过build.gradle文件,我相信我需要该文件才能在Jenkins上运行gradle构建。

任何帮助表示赞赏!


阅读 366

收藏
2020-07-25

共1个答案

小编典典

我最终从头开始创建了这些构建文件。

以下是一些准则:

  1. 如果您的项目包含多个模块,请在项目的根目录(与所有模块处于同一级别)创建settings.gradle文件。您的settings.gradle文件应如下所示:
        include 'ActionBarSherlock'
    include ':facebook-android-sdk-3.0.1:facebook'
    include 'google-play-services_lib'
    include ':SlidingMenu-master:library'
    include 'Tinder'
    include 'ViewPagerIndicator'
    include 'volley'
    include 'windowed-seek-bar'
  1. 在每个模块中,创建一个build.gradle文件。对于库项目,您的build.gradle文件应如下所示:
        buildscript {
        repositories {
            mavenCentral()
        }

        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
        }
    }

    apply plugin: 'android-library'

    dependencies {
        compile 'com.android.support:support-v4:13.0.0'
    }

    android {
        buildToolsVersion "17.0"
        compileSdkVersion 17

        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')
        }
    }
  1. 对于您的主项目,build.gradle文件应如下所示:
        buildscript {
        repositories {
            mavenCentral()
        }

        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
        }
    }

    apply plugin: 'android'

    dependencies {
        compile project(':facebook-android-sdk-3.0.1:facebook')
        compile project(':google-play-services_lib')
        compile project(':SlidingMenu-master:library')
        compile project(':ViewPagerIndicator')
        compile project(':volley')
        compile project(':windowed-seek-bar')
        compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar')
    }

    android {
        buildToolsVersion "17.0"
        compileSdkVersion 17

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }
        }
    }
2020-07-25