How to set up gradle and android studio to do release build?

前端 未结 6 1988
礼貌的吻别
礼貌的吻别 2020-12-02 07:21

I want to build android app and start signing it. For that I need to have Release version of apk. Google documentation suggests only Eclipse and ant ways to have release bu

6条回答
  •  無奈伤痛
    2020-12-02 07:47

    in the latest version of android studio, you can just do:

    ./gradlew assembleRelease
    

    or aR for short. This will produce an unsigned release apk. Building a signed apk can be done similarly or you can use Build -> Generate Signed Apk in Android Studio.

    See the docs here

    Here is my build.gradle for reference:

    buildscript {
      repositories {
        mavenCentral()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
      }
    }
    apply plugin: 'android'
    
    dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
    }
    
    android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
    
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    
        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
    
        // Move the build types to build-types/
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src//... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    
    }
    
    buildTypes {
        release {
    
        }
    }
    

提交回复
热议问题