Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build/intermediates/incremental/packageDebugResources/merged.dir/
build/intermediates/incremental/packageDebugResources/stripped.dir/
build/intermediates/incremental/processDebugAndroidTestResources/
build/intermediates/incremental/processDebugResources/
build/intermediates/jniLibs/
build/intermediates/jniLibs
build/intermediates/rs/
build/intermediates/shaders/
build/intermediates/tmp/
Expand Down
98 changes: 78 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
apply plugin: 'com.dd.comgradle'
apply plugin: 'com.android.application'
apply plugin: 'com.taobao.atlas'
apply plugin: 'com.taobao.atlas.dexpatch'
apply from: 'dexPatchWraper.gradle'


def apVersion = getEnvValue("apVersion", "");
android {

compileSdkVersion rootProject.ext.android.compileSdkVersion
Expand Down Expand Up @@ -27,6 +32,7 @@ android {
}

}
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -38,7 +44,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}
debug {
ndk {
abiFilters "x86","armeabi"
}

}
}


Expand All @@ -64,13 +75,6 @@ android {
// }


compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}
dexOptions {
jumboMode true
//jenkins上使用有问题
Expand All @@ -79,22 +83,76 @@ android {
}
}

String getEnvValue(key, defValue) {
def val = System.getProperty(key);
if (null != val) {
return val;
}
val = System.getenv(key);
if (null != val) {
return val;
}
return defValue;
}



atlas {

atlasEnabled true
tBuildConfig {
autoStartBundles = ['com.dhc.flyabbit.gank'] //自启动bundle配置
autoStartBundles = ['com.dhc.flyabbit.home'] //自启动bundle配置
autoStartBundles = ['com.dhc.flyabbit.my'] //自启动bundle配置
outOfApkBundles = ['photoview']
// outOfApkBundles = ['remotebundle']
// preLaunch = 'com.taobao.demo.DemoPreLaunch'
classInject false
// dataBindingBundles = ['com.taobao.databindbundle']
autoPackageId
}

manifestOptions {
addAtlasProxyComponents true
}


patchConfigs {
debug {
createTPatch true
}
}


buildTypes {
debug {
if (apVersion) {
baseApDependency "com.taobao.android.atlasdemo:AP-debug:${apVersion}@ap"
patchConfig patchConfigs.debug
}
}
}
}




dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation rootProject.ext.dependencies["junit"]
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile rootProject.ext.dependencies["junit"]
provided rootProject.ext.dependencies["javax.annotation"]
debugImplementation rootProject.ext.dependencies["canary-debug"]
testImplementation rootProject.ext.dependencies["canary-test"]
releaseImplementation rootProject.ext.dependencies["canary-release"]
debugCompile rootProject.ext.dependencies["canary-debug"]
testCompile rootProject.ext.dependencies["canary-test"]
releaseCompile rootProject.ext.dependencies["canary-release"]
//dagger2的apt注解
annotationProcessor rootProject.ext.dependencies["dagger-compiler"]
//阿里的Arouter的注解
annotationProcessor rootProject.ext.dependencies["arouter-compiler"]
implementation project(':businessComponent')
compile project(':businessComponent')
compile project(':activitygroupcompat')
bundleCompile project(':my')
bundleCompile project(':home')
bundleCompile project(':girls')
bundleCompile project(':photoview')
}
combuild {
applicationName = 'com.dhc.flyabbit.app.App'
isRegisterCompoAuto = true
}

118 changes: 118 additions & 0 deletions app/dexPatchWraper.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import static Constants.*


/**
* Created by 种藏 on 2017/8/30.
*
* 1. 这个类只是对产物patches.json文件做个包装,用来模拟服务器控制dexPatch版本的逻辑,生成的产物是dexpatch-versionName.json
*
* 2. 正常开发情况,做dexPatch时,服务器会分配一个对应的dexPatchVersion。
* 客户端比较dexPatchVersion来判断要不要做patch。
*
* 3. 这里只是每次做dexPatch时,简单的将dexPatchVersion 加 1.
*
* 4. 具体字段含义,参考https://alibaba.github.io/atlas/update/dexpatch_use_guide.html
*
*/

tasks.whenTaskAdded { task ->
if (task.name == "assembleDebug" || task.name == "assembleRelease") {
task.doLast {
wrapDexPatchFile(task.name.contains("Debug"))
}
}
// if (task.name == "clean") {
// task.doLast { cleanPatchVersion() }
// }
}

class Constants {
static final ENCODE_UTF_8 = "UTF-8"
static final PATH_VERSION_FILE = "dexPatch.version"
}

task tesetm << {
wrapDexPatchFile(true)
}

def wrapDexPatchFile(boolean debug) {

println "root project :${rootProject.projectDir.path}"

def apVersion = getEnvValue("apVersion", "-1")
def versionName = getEnvValue("versionName", "-1")
if (apVersion == "-1" || versionName == "-1") {
println("jump dexPatch")
return
}

if (apVersion != versionName) {
return
}


println "DexPatch wrap ,version $versionName"

String path = rootProject.projectDir.path + "/app/build/outputs/tpatch-" + (debug ? "debug" : "release") + "/patchs.json"
String patchPath = path.replace('/', File.separator)
println "patchFile path :$patchPath"

String fileContents = new File(patchPath).getText(ENCODE_UTF_8)
def patchConfig = new JsonSlurper().parseText(fileContents)
def updateInfo = patchConfig.patches[0]
updateInfo.dexPatch = true
def bundles = updateInfo.bundles
assert bundles instanceof List
def patchVersion = getPatchVersion()
bundles.each {
assert it instanceof Map
it.dexpatchVersion = patchVersion
it.isMainDex = it.mainBundle
it.remove("mainBundle")
if (it.isMainDex) {
println "=================>add empty main_dex dependency ============="
it.dependency=[]
}
}
//写回到最终的dexPatch产物文件中
String wrapFilePath = "${rootProject.projectDir.path}/app/build/outputs/tpatch-" + (debug ? "debug" : "release") + "/dexpatch-${patchConfig.baseVersion}.json"
File wrapFile = new File(wrapFilePath.replace('/', File.separator))
if (wrapFile.exists()) wrapFile.delete()
wrapFile.createNewFile()
def dexPatchJson = JsonOutput.toJson(patchConfig)
wrapFile.setText(dexPatchJson, ENCODE_UTF_8)
}

//粗暴+1
def getPatchVersion() {
File versionFile = new File(rootProject.projectDir.path, PATH_VERSION_FILE)
if (!versionFile.exists()) versionFile.createNewFile()
String versionStr = versionFile.getText(ENCODE_UTF_8)
if (null == versionStr || versionStr.isEmpty()) {
versionStr = "1"
}
String nextVersion = String.valueOf(Integer.valueOf(versionStr) + 1)
versionFile.setText(nextVersion, ENCODE_UTF_8)
return versionStr
}

def cleanPatchVersion() {
File versionFile = new File(rootProject.projectDir.path, PATH_VERSION_FILE)
if (versionFile.exists()) {
versionFile.delete()
}
}

String getEnvValue(key, defValue) {
def val = System.getProperty(key)
if (null != val) {
return val
}
val = System.getenv(key)
if (null != val) {
return val
}
return defValue
}
94 changes: 94 additions & 0 deletions app/src/main/java/com/dhc/flyabbit/DownLoadManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.dhc.flyabbit;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import okhttp3.ResponseBody;


public class DownLoadManager {

private static final String TAG = "DownLoadManager";

private static String APK_CONTENTTYPE = "application/vnd.android.package-archive";

private static String PNG_CONTENTTYPE = "image/png";

private static String JPG_CONTENTTYPE = "image/jpg";

private static String fileSuffix = "";

public static boolean writeResponseBodyToDisk(Context context, ResponseBody body, String fileName) {

Log.d(TAG, "contentType:>>>>" + body.contentType().toString());

String type = body.contentType().toString();

if (type.equals(APK_CONTENTTYPE)) {

fileSuffix = ".apk";
} else if (type.equals(PNG_CONTENTTYPE)) {
fileSuffix = ".png";
}

// 其他类型同上 自己判断加入.....

String path = context.getExternalCacheDir().getAbsolutePath();

Log.d(TAG, "path:>>>>" + path);

try {
File futureStudioIconFile = new File(path,fileName);

InputStream inputStream = null;
OutputStream outputStream = null;

try {
byte[] fileReader = new byte[4096];

long fileSize = body.contentLength();
long fileSizeDownloaded = 0;

inputStream = body.byteStream();
outputStream = new FileOutputStream(futureStudioIconFile);

while (true) {
int read = inputStream.read(fileReader);

if (read == -1) {
break;
}

outputStream.write(fileReader, 0, read);

fileSizeDownloaded += read;

Log.d(TAG, "file download: " + fileSizeDownloaded + " of " + fileSize);
}

outputStream.flush();


return true;
} catch (IOException e) {
return false;
} finally {
if (inputStream != null) {
inputStream.close();
}

if (outputStream != null) {
outputStream.close();
}
}
} catch (IOException e) {
return false;
}
}
}
Loading