优化细节

pull/27/head
Jenly 3 years ago
parent e93a677d1b
commit ff6eca1ab2
  1. 74
      README.md
  2. 12
      app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
  3. 11
      app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
  4. BIN
      app/release/app-release.apk
  5. 4
      app/release/output-metadata.json
  6. 12
      app/src/main/java/com/king/appupdater/MainActivity.java
  7. 2
      build.gradle
  8. 7
      gradle.properties
  9. 4
      versions.gradle

@ -2,7 +2,8 @@
![Image](app/src/main/ic_launcher-web.png)
[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk)
[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk)、
[![MavenCentral](https://img.shields.io/maven-central/v/com.github.jenly1314.AppUpdater/app-updater)](https://repo1.maven.org/maven2/com/github/jenly1314/AppUpdater)
[![JCenter](https://img.shields.io/badge/JCenter-1.0.10-46C018.svg)](https://bintray.com/beta/#/jenly/maven/app-updater)
[![JitPack](https://jitpack.io/v/jenly1314/AppUpdater.svg)](https://jitpack.io/#jenly1314/AppUpdater)
[![CI](https://travis-ci.org/jenly1314/AppUpdater.svg?branch=master)](https://travis-ci.org/jenly1314/AppUpdater)
@ -36,25 +37,36 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 引入
### Maven:
```maven
//app-updater
<dependency>
<groupId>com.king.app</groupId>
<artifactId>app-updater</artifactId>
<version>1.0.10</version>
<type>pom</type>
</dependency>
由于2021年2月3日 **JFrog宣布将关闭Bintray和JCenter,计划在2022年2月完全关闭。所以后续版本不再发布至 JCenter
### Gradle:
1. 在Project的 **build.gradle** 里面添加远程仓库
```gradle
allprojects {
repositories {
//...
mavenCentral()
}
}
```
2. 在Module的 **build.gradle** 里面添加引入依赖项
```gradle
//----------AndroidX 版本
//app-updater
implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.0'
//app-dialog
<dependency>
<groupId>com.king.app</groupId>
<artifactId>app-dialog</artifactId>
<version>1.0.10</version>
<type>pom</type>
</dependency>
implementation 'com.github.jenly1314.AppUpdater:app-dialog:1.1.0'
```
### Gradle:
以前发布至JCenter的版本
```gradle
//----------AndroidX 版本
@ -69,28 +81,6 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
//app-dialog
implementation 'com.king.app:app-dialog:1.0.10'
```
### Lvy:
```lvy
//app-updater
<dependency org='com.king.app' name='app-dialog' rev='1.0.10'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
//app-dialog
<dependency org='com.king.app' name='app-dialog' rev='1.0.10'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
###### 如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie)
```gradle
allprojects {
repositories {
//...
maven { url 'https://dl.bintray.com/jenly/maven' }
}
}
```
## 示例
@ -138,7 +128,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
更多使用详情,请查看[app](app)中的源码使用示例或直接查看[API帮助文档](https://jenly1314.github.io/projects/AppUpdater/doc/)
更多使用详情,请查看[app](app)中的源码使用示例或直接查看[API帮助文档](https://javadoc.jitpack.io/com/github/jenly1314/AppUpdater/1.1.0/javadoc/index.html)
## 混淆
@ -148,6 +138,10 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录
#### v1.1.0:2021-7-2 (从v1.1.0开始不再发布至JCenter)
* 后续版本只支持androidx,版本名称不再带有androidx标识
* 优化细节
#### v1.0.10:2021-3-4
* AppDialogConfig添加构造参数,简化自定义扩展用法
* 优化细节

@ -73,7 +73,7 @@ public class DownloadService extends Service {
UpdateConfig config = intent.getParcelableExtra(Constants.KEY_UPDATE_CONFIG);
startDownload(config,null,null);
}else{
Log.w(Constants.TAG,"Please do not repeat the download.");
Log.w(Constants.TAG,"Please do not duplicate downloads.");
}
}
@ -96,12 +96,12 @@ public class DownloadService extends Service {
return;
}
if(callback!=null){
if(callback != null){
callback.onDownloading(isDownloading);
}
if(isDownloading){
Log.w(Constants.TAG,"Please do not repeat the download.");
Log.w(Constants.TAG,"Please do not duplicate downloads.");
return;
}
@ -131,9 +131,11 @@ public class DownloadService extends Service {
//是否存在相同的apk
boolean isExistApk = false;
if(!TextUtils.isEmpty(apkMD5)){//如果存在MD5,则优先校验MD5
Log.d(Constants.TAG,String.format("UpdateConfig.apkMD5:%d",apkMD5));
isExistApk = AppUtils.checkFileMD5(mFile,apkMD5);
}else if(versionCode!=null){//如果存在versionCode,则校验versionCode
}else if(versionCode != null){//如果存在versionCode,则校验versionCode
try{
Log.d(Constants.TAG,String.format("UpdateConfig.versionCode:%d",versionCode));
isExistApk = AppUtils.apkExists(getContext(),versionCode,mFile);
}catch (Exception e){
Log.w(Constants.TAG,e);
@ -303,7 +305,7 @@ public class DownloadService extends Service {
}
}
if(callback!=null){
if(callback != null){
callback.onProgress(progress,total,isChange);
}
}

@ -154,10 +154,13 @@ public final class AppUtils {
if(file!=null && file.exists()){
String packageName = context.getPackageName();
PackageInfo packageInfo = AppUtils.getPackageInfo(context,file.getAbsolutePath());
if(packageInfo!=null && versionCode == packageInfo.versionCode){//比对versionCode
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
if(applicationInfo!=null && packageName.equals(applicationInfo.packageName)){//比对packageName
return true;
if(packageInfo != null){//比对versionCode
Log.d(Constants.TAG,String.format("ApkVersionCode:%d",packageInfo.versionCode));
if(versionCode == packageInfo.versionCode){
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
if(applicationInfo != null && packageName.equals(applicationInfo.packageName)){//比对packageName
return true;
}
}
}
}

Binary file not shown.

@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 18,
"versionName": "1.0.10-androidx",
"versionCode": 19,
"versionName": "1.1.0",
"outputFile": "app-release.apk"
}
]

@ -3,6 +3,7 @@ package com.king.appupdater;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
@ -30,6 +31,8 @@ import androidx.appcompat.app.AppCompatActivity;
*/
public class MainActivity extends AppCompatActivity {
private static String TAG = MainActivity.class.getSimpleName();
private final Object mLock = new Object();
//下载出现Failed to connect to raw.githubusercontent.com时,可以换个下载链接测试,github的raw.githubusercontent.com目前不太稳定。
@ -92,6 +95,8 @@ public class MainActivity extends AppCompatActivity {
public void onDownloading(boolean isDownloading) {
if(isDownloading){
showToast("已经在下载中,请勿重复下载。");
}else{
showToast("开始下载…");
}
}
@ -103,10 +108,11 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onProgress(long progress, long total, boolean isChange) {
int currProgress = (int)(progress * 1.0f / total * 100.0f);
if(isChange){
int currProgress = Math.round(progress * 1.0f / total * 100.0f);
progressBar.setProgress(currProgress);
}
Log.d(TAG,String.format("onProgress:%d/%d | %d%%",progress,total,currProgress));
}
@Override
@ -143,7 +149,7 @@ public class MainActivity extends AppCompatActivity {
.setUpdateCallback(new AppUpdateCallback() {
@Override
public void onProgress(long progress, long total, boolean isChange) {
Log.d(TAG,String.format("onProgress:%d/%d",progress,total));
}
@Override
@ -222,8 +228,6 @@ public class MainActivity extends AppCompatActivity {
public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder()
.setUrl(mUrl)
// .setPath(Environment.getExternalStorageDirectory() + "/.AppUpdater")//如果适配Android Q,则Environment.getExternalStorageDirectory()将废弃
// .setPath(getExternalFilesDir(Constants.DEFAULT_DIR).getAbsolutePath())//自定义路径,推荐使用默认
// .setApkMD5("3df5b1c1d2bbd01b4a7ddb3f2722ccca")//支持MD5校验,如果缓存APK的MD5与此MD5相同,则直接取本地缓存安装,推荐使用MD5校验的方式
.setVersionCode(BuildConfig.VERSION_CODE)//支持versionCode校验,设置versionCode之后,新版本versionCode相同的apk只下载一次,优先取本地缓存,推荐使用MD5校验的方式
.setFilename("AppUpdater.apk")

@ -8,7 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.novoda:bintray-release:0.9'
// classpath 'com.novoda:bintray-release:0.9'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.13.0'
// NOTE: Do not place your application dependencies here; they belong

@ -17,8 +17,8 @@ android.enableJetifier=true
VERSION_NAME=1.0.10-androidx
VERSION_CODE=18
VERSION_NAME=1.1.0
VERSION_CODE=19
GROUP=com.github.jenly1314.AppUpdater
POM_DESCRIPTION=AppUpdater for Android
@ -34,4 +34,5 @@ POM_DEVELOPER_ID=jenly
POM_DEVELOPER_NAME=Jenly Yu
RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots/
RELEASE_SIGNING_ENABLED=true
RELEASE_SIGNING_ENABLED=false

@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 18 //androidx 18
app_version.versionName = "1.0.10-androidx"
app_version.versionCode = 19
app_version.versionName = "1.1.0"
ext.app_version = app_version
//build version

Loading…
Cancel
Save