| 1 | | '''qq''' |
| | 1 | |
| | 2 | == 生成keystore : == |
| | 3 | [http://blog.sina.com.cn/s/blog_4b93170a0100qp7z.html] |
| | 4 | |
| | 5 | |
| | 6 | |
| | 7 | == win7使用开发工具Eclipse,gradle多渠道打包 == |
| | 8 | '''注意:''' |
| | 9 | [[BR]]1、配置好gradle的环境变量(在path中配置他的bin目录)。 |
| | 10 | [[BR]]2、配置好ANDROID_HOME 的环境变量。 |
| | 11 | [[BR]]3、利用Eclipse工具自动生成build.gradle文件。选择工程右击:Export--> Android --> Generate gradle build file --> 接下来的步骤是生成build.gradle. |
| | 12 | |
| | 13 | == 代码示例:聚超值 == |
| | 14 | |
| | 15 | ''jucaozhi:'' |
| | 16 | |
| | 17 | |
| | 18 | {{{ |
| | 19 | |
| | 20 | |
| | 21 | |
| | 22 | apply plugin: 'android' |
| | 23 | |
| | 24 | dependencies { |
| | 25 | compile fileTree(dir: 'libs', include: '*.jar') |
| | 26 | compile project(':pcgCommon') |
| | 27 | } |
| | 28 | |
| | 29 | android { |
| | 30 | compileSdkVersion 17 |
| | 31 | buildToolsVersion "21.0.1" |
| | 32 | |
| | 33 | sourceSets { |
| | 34 | main { |
| | 35 | manifest.srcFile 'AndroidManifest.xml' |
| | 36 | java.srcDirs = ['src'] |
| | 37 | resources.srcDirs = ['src'] |
| | 38 | aidl.srcDirs = ['src'] |
| | 39 | renderscript.srcDirs = ['src'] |
| | 40 | res.srcDirs = ['res'] |
| | 41 | assets.srcDirs = ['assets'] |
| | 42 | } |
| | 43 | |
| | 44 | // Move the tests to tests/java, tests/res, etc... |
| | 45 | instrumentTest.setRoot('tests') |
| | 46 | |
| | 47 | |
| | 48 | lintOptions { |
| | 49 | abortOnError false |
| | 50 | } |
| | 51 | // Move the build types to build-types/<type> |
| | 52 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... |
| | 53 | // This moves them out of them default location under src/<type>/... which would |
| | 54 | // conflict with src/ being used by the main source set. |
| | 55 | // Adding new build types or product flavors should be accompanied |
| | 56 | // by a similar customization. |
| | 57 | //debug.setRoot('build-types/debug') |
| | 58 | //release.setRoot('build-types/release') |
| | 59 | } |
| | 60 | |
| | 61 | signingConfigs { |
| | 62 | myConfig { |
| | 63 | storeFile file("gradle.keystore") |
| | 64 | storePassword "gradle" |
| | 65 | keyAlias "gradle.keystore" |
| | 66 | keyPassword "gradle" |
| | 67 | } |
| | 68 | } |
| | 69 | |
| | 70 | buildTypes { |
| | 71 | debug { |
| | 72 | signingConfig signingConfigs.debug |
| | 73 | } |
| | 74 | /* release { |
| | 75 | signingConfig signingConfigs.release |
| | 76 | }*/ |
| | 77 | } |
| | 78 | |
| | 79 | productFlavors { |
| | 80 | //加入渠道号 |
| | 81 | GooglePlay{} |
| | 82 | wandoujia{} |
| | 83 | 360zhushou{} |
| | 84 | } |
| | 85 | |
| | 86 | } |
| | 87 | |
| | 88 | |
| | 89 | |
| | 90 | }}} |
| | 91 | |
| | 92 | |
| | 93 | |
| | 94 | ''pcgCommon:'' |
| | 95 | |
| | 96 | {{{ |
| | 97 | |
| | 98 | apply plugin: 'android-library' |
| | 99 | |
| | 100 | dependencies { |
| | 101 | compile fileTree(dir: 'libs', include: '*.jar') |
| | 102 | } |
| | 103 | |
| | 104 | android { |
| | 105 | compileSdkVersion 17 |
| | 106 | buildToolsVersion "21.0.1" |
| | 107 | |
| | 108 | sourceSets { |
| | 109 | main { |
| | 110 | manifest.srcFile 'AndroidManifest.xml' |
| | 111 | java.srcDirs = ['src'] |
| | 112 | resources.srcDirs = ['src'] |
| | 113 | aidl.srcDirs = ['src'] |
| | 114 | renderscript.srcDirs = ['src'] |
| | 115 | res.srcDirs = ['res'] |
| | 116 | assets.srcDirs = ['assets'] |
| | 117 | } |
| | 118 | |
| | 119 | // Move the tests to tests/java, tests/res, etc... |
| | 120 | instrumentTest.setRoot('tests') |
| | 121 | |
| | 122 | // Move the build types to build-types/<type> |
| | 123 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... |
| | 124 | // This moves them out of them default location under src/<type>/... which would |
| | 125 | // conflict with src/ being used by the main source set. |
| | 126 | // Adding new build types or product flavors should be accompanied |
| | 127 | // by a similar customization. |
| | 128 | debug.setRoot('build-types/debug') |
| | 129 | release.setRoot('build-types/release') |
| | 130 | |
| | 131 | lintOptions { |
| | 132 | abortOnError false |
| | 133 | } |
| | 134 | } |
| | 135 | } |
| | 136 | |
| | 137 | |
| | 138 | }}} |
| | 139 | |
| | 140 | |
| | 141 | |
| | 142 | |
| | 143 | == 命令 == |
| | 144 | 例如:进入到juchaozhi目录下,输入gradle build |
| | 145 | |
| | 146 | |
| | 147 | |
| | 148 | == 错误提示 == |
| | 149 | |
| | 150 | [[BR]]1、图片资源文件中可能误。修改建议:删除图片文件或者修改格式 |
| | 151 | [[BR]]2、values文件中,可能value,string等里面有重复的类容。修改建议,删除重复类容 |
| | 152 | [[BR]]3、例如依赖包“pcgComon ”中的<application>....</application>会与“jucaozhi”中的<application>发生冲突,修改建议:注释掉依赖包中<application>....</application> |
| | 153 | [[BR]]4、在打包过程中会出现很多错误,看dos窗口输出的错误进行修改就可以了。 |
| | 154 | |
| | 155 | |
| | 156 | |
| | 157 | == 建议 == |
| | 158 | 使用android studio开发工具打包,该工具会直接提示错误位置,节省我们找错误的原因。 |
| | 159 | |
| | 160 | == 更多详细的代码解释: == |
| | 161 | [http://trac.pc.com.cn/gzandroid/wiki/gradle] |
| | 162 | |
| | 163 | |