Android Studio: How to create build.gradle file for use on Jenkins?

前端 未结 1 1131
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 18:33

I\'m new to gradle and trying to figure out how to set it up on our Jenkins build machine. Our app builds perfectly from within Android Studio, but it doesn\'t ever generate a b

1条回答
  •  别那么骄傲
    2021-02-08 19:23

    I ended up creating these build files from scratch.

    Here's some guidelines:

    1. If you have a project with multiple modules, create a settings.gradle file at the root of your project (at the same level as all the modules). Your settings.gradle file should look something like this:

      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'
      
    2. Within each module, create a build.gradle file. For library projects, your build.gradle file should look something like this:

      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')
          }
      }
      
    3. For your main project, your build.gradle file should look like this:

      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']
              }
          }
      }
      

    0 讨论(0)
提交回复
热议问题