android studio gradle
1:build.gradle文件下的一些基本概念
apply plugin: 'android'
def outputDir = "C:/Users/jian_zhou/Desktop/myapk"
def startName = "start"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile files('libs/bugly_1.2.3.8__release.jar')
compile files('libs/CySDK.jar')
compile files('libs/fastjson-1.1.45.android.jar')
compile files('libs/httpmime-4.1.2.jar')
compile files('libs/jg_filter_sdk_1.1.jar')
compile files('libs/mframework.jar')
compile files('libs/mid-sdk-2.20.jar')
compile files('libs/MobLogCollector.jar')
compile files('libs/MobTools.jar')
compile files('libs/mta-sdk-2.0.2.jar')
compile files('libs/RasterSDKv1.1.0.15299.jar')
compile files('libs/ShareSDK-Core-2.6.1.jar')
compile files('libs/ShareSDK-Email-2.6.1.jar')
compile files('libs/ShareSDK-QQ-2.6.1.jar')
compile files('libs/ShareSDK-QZone-2.6.1.jar')
compile files('libs/ShareSDK-ShortMessage-2.6.1.jar')
compile files('libs/ShareSDK-SinaWeibo-2.6.1.jar')
compile files('libs/ShareSDK-Wechat-2.6.1.jar')
compile files('libs/ShareSDK-Wechat-Core-2.6.1.jar')
compile files('libs/ShareSDK-Wechat-Moments-2.6.1.jar')
compile files('libs/TencentLocationSDK_v4.1.1_r175129.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/wup-1.0.0-SNAPSHOT.jar')
compile files('libs/Xg_sdk_v2.39_20150915_1121.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/eventbus.jar')
}
android {
signingConfigs {
config {
keyAlias 'cmstop'
keyPassword 'cmstop'
storeFile file('C:/Users/jian_zhou/Desktop/cmstop.keystore')
storePassword 'cmstop'
}
}
//忽略lint错误
lintOptions{
abortOnError false
}
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.wondertek.cj_yun"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'unvariable', 'variable']
resources.srcDirs = ['src', 'unvariable', 'variable']
aidl.srcDirs = ['src', 'unvariable', 'variable']
renderscript.srcDirs = ['src', 'unvariable', 'variable']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
// proguardFile 'proguard.cfg'
proguardFile 'proguard.cfg'
signingConfig signingConfigs.config
// zipAlignEnabled true
}
debug {
signingConfig signingConfigs.config
}
}
//apk 输出目的路径的写法
android.applicationVariants.all { variant ->
def file = variant.outputs[0].outputFile
def fileParent = new File(outputDir)
variant.outputs[0].outputFile =
new File(fileParent,startName +"_"+name+ ".apk")
}
}
2:gradle 命令区别学习(http://www.androidchina.net/2155.html)
http://segmentfault.com/a/1190000002464822
assemble 构建项目输出
check 运行检测和测试任务
build 运行assemble和check
clean 清理输出任务
执行任务可以通过gradle/gradlew+任务名称的方式执,执行一个顶级任务会同时执行与其依赖的任务,比如你执行
gradlew assemble
它通常会执行:
gradlew assembleDebug
gradlew assembleRelease
3:AndroidManifest.xml下package="com.wondertek.cj_yun"与build.gradle 下applicationId的疑问
http://blog.csdn.net/maosidiaoxian/article/details/41719357
4:Android 自定义控件在Android Studio中xmlns不识别
Gradle工具会自动识别,所以不用指定包名
把 xmlns:xx="http://schemas.android.com/apk/res/com.xxx"
换成 xmlns:xx="http://schemas.android.com/apk/res-auto"
然后同步一下 就OK了
5:Gradle 的详情
http://wiki.jikexueyuan.com/project/gradle-2-user-guide/
6:java 代码执行动态gradle命令打包
private static void fun1() { // TODO Auto-generated method stub // 使用 && 来连接两条命令 String cmd = "cmd /c D: && cd D:\\WorkSource\\Android_Studio\\CmsTopCloudMobile && gradle assemblerelease"; // 使用数组 String[] cmds = new String[] { "cmd", "/k", " start ", "notepad" }; Runtime run = Runtime.getRuntime(); try { Process process = run.exec(cmd); // 用缓冲器读行 BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; // 直到读完为止 while ((line = reader.readLine()) != null) { System.out.println("xxx---->"+line); if(line.contains("SUCCESSFUL")){ System.out.println("打包成功了"+line); return ; }else if(line.contains("FAILED")){ System.out.println("打包失败了"+line); return ; } } reader.close(); process.waitFor(); process.destroy(); } catch (Exception e) { e.printStackTrace(); } }
cmd 打包用到的一些命令符
cmd /c dir 是执行完dir命令后关闭命令窗口。
cmd /k dir 是执行完dir命令后不关闭命令窗口。
cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。
cmd /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。
7:java代码执行自动打包时Runtime.getRuntime().exec 的问题
主要是主控程序的waitfor方法会被阻塞一直等待下去 需要自己手动处理一下 请参考
http://jasonshieh.iteye.com/blog/1144891
posted on 2015-12-28 15:20 yujian_bcq 阅读(599) 评论(0) 编辑 收藏 举报