圖文來教你在eclipse下用gradle 來打包Android,gradleandroid

來源:互聯網
上載者:User

圖文來教你在eclipse下用gradle 來打包Android,gradleandroid

gradle其他好處就不多說,在android應用發布的時候,如果要統計多個渠道,gradle 批量打包的好處就顯示出來了;下面介紹圖文來介紹

按eclipse的匯出時 選擇Android;如 然後按下面一步一步往下點



點擊完成之後 工程裡面就產生了如下的幾個檔案;也就是gradle的設定檔


開啟gradle-wrapper.properties這個檔案;可以看到distributionUrl這個地址;而這個地址就是gradle的;在瀏覽器開啟下載 如:


將下載的檔案押解出來;然後需要設定系統內容變數;需要設定變數名:GRADLE_HOME變數值為:C:\xiong\gradle-1.10-all\gradle-1.10(也就是你下載的Gradle檔案的根目錄)然後設定path;在後面加上C:\xiong\gradle-1.10-all\gradle-1.10\bin 如




然後運行在cmd中運行gradle -v來判斷是否設定成功 如


確定安裝成功之後就基本可以運行gradle命令來打包了;將cmd命令定位到工程的根目錄,然後運行gradle bulid





如果需要批量打包;則在build.gradle進行配置

原始eclipse產生的檔案內容如下

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'com.android.tools.build:gradle:0.8.+'    }}apply plugin: 'android'dependencies {    compile fileTree(dir: 'libs', include: '*.jar')}android {    compileSdkVersion 19    buildToolsVersion "19.0.3"    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/<type>        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...        // This moves them out of them default location under src/<type>/... 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')    }}
只要在如上代碼中添加就可以  比如

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'com.android.tools.build:gradle:0.8.+'    }}apply plugin: 'android'dependencies {    compile fileTree(dir: 'libs', include: '*.jar')}android {    compileSdkVersion 19    buildToolsVersion "19.0.3"    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/<type>        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...        // This moves them out of them default location under src/<type>/... 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')            //批量打包--指定設定檔          //不同的渠道商對應的各自AndroidManifest          //AndroidManifest的application標籤只用配置渠道號的值          //其他公用配置都放在公用的AndroidManifest.xml中          one {         manifest.srcFile 'tests/AndroidManifest1.xml'      }      two {         manifest.srcFile 'tests/AndroidManifest2.xml'      }          instrumentTest.setRoot('tests')              }             //批量打包--聲明      productFlavors {      one {              //這裡可以配置不同的包名      }      two {      }      }       //簽名      signingConfigs {        myConfig {            storeFile file("11.keystore")      //簽名檔案            storePassword "111111"                keyAlias "111111"                         keyPassword "111111"  //簽名密碼        }      }  }


至於其他的 俺就不說了 不動找度娘

demo下載

轉載請註明出處:http://blog.csdn.net/x605940745


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.