MCPcopy Index your code
hub / github.com/appspa/app-space-android

github.com/appspa/app-space-android @1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.1 ↗ · + Follow
814 symbols 2,144 edges 73 files 422 documented · 52% updated 3y ago1.0.0 · 2023-03-22★ 176
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

XUpdate

api I Star

English | ChineseVideo tutorial

A lightweight, high availability Android version update framework. Click instruction document to experience it!

Please read 【wisdom of asking questions】 before raising the issue and strictly follow the issue template fill in and save everyone's time.

Please read the instruction document carefully before use, important things are to be repeated for three time!!!

Please read the instruction document carefully before use, important things are to be repeated for three time!!!

Please read the instruction document carefully before use, important things are to be repeated for three time!!!

About me

WeChat public number juejin zhihu CSDN jianshu segmentfault bilibili toutiao
我的Android开源之旅 Click me Click me Click me Click me Click me Click me Click me

Simplify use

If you want to use xupdate faster, reduce the difficulty of integration, support breakpoint continuation download and other expansion functions, you can try to use XUpdateAPI.

Rapid integration of X-Library

In order to facilitate the rapid integration of X-Library, I provide a template project for your reference: https://github.com/xuexiangjys/TemplateAppProject


Features

  • It supports Post or Get request to check version, and supports user-defined network requests.

  • Only version update under WiFi is supported。

  • Support silent download (background update) and automatic version update.

  • The user-friendly version update prompt pop-up window is provided to customize the theme style.

  • It supports user-defined version update checker, parser, prompter, downloader, install listener and error listener.

  • Support MD5 file verification, version ignore, version forced update and other functions.

  • It supports the user-defined file verification method【MD5 verification by default】.

  • Support custom request API interface.

  • Compatible with Android 6.0 ~ 11.0.

  • Support Chinese and English language (internationalization).

  • Support the use of the flutter plugin:flutter_xupdate

  • Support the use of react native plugin:react-native-xupdate

Stargazers over time

Stargazers over time

Composition structure

This framework refers to AppUpdate some ideas and UI, the various parts of the version update are separated to form the following parts:

  • IUpdateChecker: Check for the latest version.

  • IUpdateParser: Parsing the data results returned by the server.

  • IUpdatePrompter: Display the latest version information.

  • IUpdateDownloader: Download the latest version of APK installation package.

  • IUpdateHttpService: The interface for network request.

In addition, there are two listeners:

  • OnUpdateFailureListener: Listening error

  • OnInstallListener: Callback of application installation

Update core manager:

  • IUpdateProxy: Responsible for the process control of version update, calling update to start the version update process.

Update process

Process after calling update:

IUpdateProxy/XUpdate --- (update) ---> IUpdateChecker --->(Request the server to get the latest version information)---> IUpdateParser ---> (Parse the data returned by the server, and build the UpdateEntity)---> IUpdateProxy ---> (If there is no latest version, end it directly, otherwise proceed to the following process)

    ---Automatic mode---> IUpdateDownloader ---> (Download the latest app apk) ---> Install application

    ---Non automatic mode---> IUpdatePrompter ---> Prompt for version update

                                                        ---> click Update ---> IUpdateDownloader ---> (Download the latest app apk) ---> Jump to application installation UI

                                                        ---> Click cancel or ignore ---> End

Click to view the framework UML design diagram


1、Demonstration

  • Default version update

xupdate_default.png

  • Background update

xupdate_background.png

  • Force version update

xupdate_force.png

  • Ignored version update

xupdate_ignore.png

  • Custom pop up theme

xupdate_custom.png

  • Use the system pop-up prompt

xupdate_system.png

Demo update background service

Because GitHub is slow to visit recently, if you need to experience xupdate better, you can Click to build a simple version update service.

Demo Download

Pgyer Download

Pgyer Download password: xuexiangjys

downloads

xupdate_download_pugongying.png

GitHub Download

downloads

xupdate_download.png


2、Quick integration guide

At present, it supports the use of the mainstream development tool AndroidStudio and add dependency by configures build.gradle directly.

2.1、Add gradle dependency

1.In the project root directory build.gradle:

allprojects {
     repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}
  1. Then add in the dependencies of build.gradle of the application project (usually app):

The following is the version description. Choose one.

  • androidx project: above 2.0.0
dependencies {
  ...
  // androidx project
  implementation 'com.github.xuexiangjys:XUpdate:2.1.3'
}
  • support project: below 1.1.6
dependencies {
  ...
  // support project
  implementation 'com.github.xuexiangjys:XUpdate:1.1.6'
}

2.2、Initialization

Initialize settings at the top of the application:

XUpdate.get()
    .debug(true)
    .isWifiOnly(true)                                               // By default, only version updates are checked under WiFi
    .isGet(true)                                                    // The default setting uses Get request to check versions
    .isAutoMode(false)                                              // The default setting is non automatic mode
    .param("versionCode", UpdateUtils.getVersionCode(this))         // Set default public request parameters
    .param("appKey", getPackageName())
    .setOnUpdateFailureListener(new OnUpdateFailureListener() {     // Set listening for version update errors
        @Override
        public void onFailure(UpdateError error) {
            if (error.getCode() != CHECK_NO_NEW_VERSION) {          // Handling different errors
                ToastUtils.toast(error.toString());
            }
        }
    })
    .supportSilentInstall(true)                                     // Set whether silent installation is supported. The default is true
    .setIUpdateHttpService(new OKHttpUpdateHttpService())           // This must be set! Realize the network request function.
    .init(this);                                                    // This must be initialized

【note】: if there is any problem, you can open debug mode to track the problem. If you also need to log on disk, you can implement the following interface.

XUpdate.get().setILogger(new ILogger() {
    @Override
    public void log(int priority, String tag, String message, Throwable t) {
        // Realize the function of logging
    }
});

2.3、Version update entity information

(1) UpdateEntity

Field name Type Default value Description
mHasUpdate boolean false Whether have the latest version
mIsForce boolean false Force installation: app cannot be used without installation
mIsIgnorable boolean false Whether the version can be ignored
mVersionCode int 0 Latest version code
mVersionName String unknown_version Latest version name
mUpdateContent String "" Update content
mDownloadEntity DownloadEntity Download information entity
mIsSilent boolean false Whether to download silently: when there is a new version, do not prompt to download directly
mIsAutoInstall boolean true Whether to automatic install app when the download is completed

(2) DownloadEntity

Field name Type Default value Description
mDownloadUrl String "" Download address
mCacheDir String "" File download directory
mMd5 String "" The encrypted check value of the downloaded file (MD5 encryption is used by default), which is used to verify and prevent the downloaded APK file from being replaced (the latest demo has a tool for calculating the check value). Note that the MD5 value here is not the MD5 value of the application signature file!
mSize long 0 Size of download file【unit: KB】
mIsShowNotification boolean false Whether to show download progress in the notification bar

(3) PromptEntity

Field name Type Default value Description
mThemeColor int R.color.xupdate_default_theme_color Theme colors (background colors for progress bars and buttons)
mTopResId int R.drawable.xupdate_bg_app_top Top background image resource ID
mTopDrawableTag String "" Top background image drawable tag
mButtonTextColor int 0 Button text color
mSupportBackgroundUpdate boolean false Whether background updates are supported
mWidthRatio float -1(Unconstrained) The ratio of the width of the version update prompter to the screen
mHeightRatio float -1(Unconstrained) The ratio of the height of the version update prompter to the screen
mIgnoreDownloadError boolean false Whether to ignore the download exception (the update prompt box will not disappear if the download fails)

2.4、File encryption verification method

The default file encryption verification method used in this framework is MD5 encryption. Of course, if you don't want to use MD5 encryption, you can also customize the File Encryptor IFileEncryptor. The following is the implementation of MD5 File Encryptor for reference:

/**
 * The default file encryption calculation uses MD5 encryption
 *
 * @author treexi
 * @since 2019-09-06 14:21
 */
public class DefaultFileEncryptor implements IFileEncryptor {
    /**
     * Encrypted files
     *
     * @param file
     * @return
     */
    @Override
    public String encryptFile(File file) {
        return Md5Utils.getFileMD5(file);
    }

    /**
     * Verify that the file is valid (whether the encryption is consistent)
     *
     * @param encrypt The encrypted value, is considered to be valid if encrypt is empty.
     * @param file    File to be verified
     * @return Whether the document is valid
     */
    @Override
    public boolean isFileValid(String encrypt, File file) {
        return TextUtils.isEmpty(encrypt) || encrypt.equalsIgnoreCase(encryptFile(file));
    }
}

Finally, call the XUpdate.get().setIFileEncryptor method, settings will take effect.


3、Version update

3.1、Default version update

You can directly call the following code to complete the version update operation:

XUpdate.newBuild(getActivity())
        .updateUrl(mUpdateUrl)
        .update();

It should be noted that with the default version update, the JSON format returned by the request server should include the following contents:

{
  "Code": 0,
  "Msg": "",
  "UpdateStatus": 1,
  "VersionCode": 3,
  "VersionName": "1.0.2",
  "ModifyContent": "1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
  "DownloadUrl": "https://raw.githubusercontent.com/xuexiangjys/XUpdate/master/apk/xupdate_demo_1.0.2.apk",
  "ApkSize": 2048,
  "ApkMd5": ""
}

Field description:

  • Code: 0 means the request is successful, non-0 means failure.
  • Msg: Request error information.
  • UpdateStatus: 0 means no update, 1 means version update, no forced upgrade is required, and 2 represents version update and forced upgrade is required.
  • VersionCode: Version number, self incrementing. Used to compare whether the version is the latest version.
  • VersionNa

Extension points exported contracts — how you extend this code

IDownloadEventHandler (Interface)
下载事件处理者 @author treexi @since 2020/12/23 10:47 PM [6 implementers]
app-space-update/src/main/java/com/appspa/update/widget/IDownloadEventHandler.java
IUpdateParser (Interface)
版本更新解析器[异步解析和同步解析方法只需要实现一个就行了,当isAsyncParser为true时需要实现异步解析方法,否则实现同步解析方法] @author treexi @since 2018/6/29 下午8:30 [5 implementers]
app-space-update/src/main/java/com/appspa/update/proxy/IUpdateParser.java
IWindowShower (Interface)
窗口显示接口 [4 implementers]
app-space-update/src/main/java/com/appspa/update/utils/DialogUtils.java
OnFileDownloadListener (Interface)
下载服务下载监听 @author treexi @since 2018/7/10 上午10:05 [4 implementers]
app-space-update/src/main/java/com/appspa/update/service/OnFileDownloadListener.java
IUpdateDownloader (Interface)
版本更新下载器 @author treexi @since 2018/6/29 下午8:31 [4 implementers]
app-space-update/src/main/java/com/appspa/update/proxy/IUpdateDownloader.java

Core symbols most depended-on inside this repo

get
called by 36
app-space-update/src/main/java/com/appspa/update/AppSpace.java
getContext
called by 35
app-space-update/src/main/java/com/appspa/update/proxy/IUpdateProxy.java
getString
called by 34
app-space-update/src/main/java/com/appspa/update/widget/BaseDialog.java
findViewById
called by 27
app-space-update/src/main/java/com/appspa/update/widget/BaseDialog.java
onUpdateError
called by 21
app-space-update/src/main/java/com/appspa/update/_AppSpace.java
update
called by 20
app-space-update/src/main/java/com/appspa/update/proxy/IUpdateProxy.java
getContext
called by 17
app-space-update/src/main/java/com/appspa/update/AppSpace.java
newBuild
called by 17
app-space-update/src/main/java/com/appspa/update/AppSpace.java

Shape

Method 726
Class 66
Interface 21
Enum 1

Languages

Java100%

Modules by API surface

app-space-update/src/main/java/com/appspa/update/UpdateManager.java53 symbols
app-space-update/src/main/java/com/appspa/update/widget/NumberProgressBar.java41 symbols
app-space-update/src/main/java/com/appspa/update/entity/UpdateEntity.java37 symbols
app-space-update/src/main/java/com/appspa/update/widget/UpdateDialogFragment.java33 symbols
app-space-update/src/main/java/com/appspa/update/utils/UpdateUtils.java32 symbols
app-space-update/src/main/java/com/appspa/update/service/DownloadService.java31 symbols
app-space-update/src/main/java/com/appspa/update/widget/UpdateDialogActivity.java30 symbols
app-space-update/src/main/java/com/appspa/update/widget/UpdateDialog.java29 symbols
app-space-update/src/main/java/com/appspa/update/_AppSpace.java26 symbols
app-space-update/src/main/java/com/appspa/update/AppSpace.java26 symbols
app-space-update/src/main/java/com/appspa/update/utils/FileUtils.java24 symbols
app-space-update/src/main/java/com/appspa/update/entity/PromptEntity.java23 symbols

For agents

$ claude mcp add app-space-android \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact