== 生成keystore : == [http://blog.sina.com.cn/s/blog_4b93170a0100qp7z.html] == win7使用开发工具Eclipse,gradle多渠道打包 == '''注意:''' [[BR]]1、配置好gradle的环境变量(在path中配置他的bin目录)。 [[BR]]2、配置好ANDROID_HOME 的环境变量。 [[BR]]3、利用Eclipse工具自动生成build.gradle文件。选择工程右击:Export--> Android --> Generate gradle build file --> 接下来的步骤是生成build.gradle. == 代码示例:聚超值 == ''jucaozhi:'' {{{ apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile project(':pcgCommon') } android { compileSdkVersion 17 buildToolsVersion "21.0.1" 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') lintOptions { abortOnError false } // 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') } signingConfigs { //加入keystore签名 myConfig { //文件路径和文件名 storeFile file("gradle.keystore") //keystore文件密码 storePassword "gradle" //别名 keyAlias "gradle.keystore" //别名密码 keyPassword "gradle" } } buildTypes { debug { signingConfig signingConfigs.debug } /* release { signingConfig signingConfigs.release }*/ } productFlavors { //加入渠道号 GooglePlay{} wandoujia{} 360zhushou{} } } }}} ''pcgCommon:'' {{{ apply plugin: 'android-library' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { compileSdkVersion 17 buildToolsVersion "21.0.1" 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') lintOptions { abortOnError false } } } }}} == 命令 == 输入gradle build [[BR]]例如:进入到juchaozhi目录下,输入gradle build == 错误提示 == [[BR]]1、图片资源文件中可能误。修改建议:删除图片文件或者修改格式 [[BR]]2、values文件中,可能value,string等里面有重复的类容。修改建议,删除重复类容 [[BR]]3、例如依赖包“pcgComon ”中的....会与“jucaozhi”中的发生冲突,修改建议:注释掉依赖包中.... [[BR]]4、在打包过程中会出现很多错误,看dos窗口输出的错误进行修改就可以了。 == 建议 == 使用android studio开发工具打包,该工具会直接提示错误位置,节省我们找错误的原因。 以上由石景城测试整理,陈鹏也整理了一份 [http://trac.pc.com.cn/gzandroid/attachment/wiki/window/Gradle%E6%B8%A0%E9%81%93%E6%B7%B7%E6%B7%86%E6%89%93%E5%8C%85.doc 下载] == 更多详细的代码解释: == [http://trac.pc.com.cn/gzandroid/wiki/gradle]