weex更新js文件和安卓apk

android部分代码

IOS请自行绕道

最近老板一直催我写一个东西,就是类似热更新的东西。要求看起来很简单,weex打包成js文件,js文件生成一个全量的zip,还有一个增量的zip,然后对应一个版本号。并且顺便把apk更新也做了,而且跟我说没有后台配合,要求我直接用文件的形式来写json。

PS:为什么写这个东西,因为我没干劲,没思路,不想写,写个文章可以逼着我写思路,写东西

Server

服务器部分用tomcat随便搞一下

首先你要有个tomcat,自己去下个idea,怎么配置idea web项目怎么运行tomcat自行百度,我也不会vert.x暂时先这样tomcat比较简单。

项目结构

这里写图片描述
version文件重的内容

{
    "android_url": "/app.apk",
    "android_vs": "2",
    "js_full_zip": "/full.zip",
    "js_vs": "10",
    "patch": [
        {
            "js_vs": "10",
            "package": "/patch_10.zip"
        },
        {
            "js_vs": "9",
            "package": "/patch_9.zip"
        },
        {
            "js_vs": "8",
            "package": "/patch_8.zip"
        },
        {
            "js_vs": "7",
            "package": "/patch_7.zip"
        },
        {
            "js_vs": "6",
            "package": "/patch_6.zip"
        },
        {
            "js_vs": "5",
            "package": "/patch_5.zip"
        },
        {
            "js_vs": "4",
            "package": "/patch_4.zip"
        },
        {
            "js_vs": "3",
            "package": "/patch_3.zip"
        },
        {
            "js_vs": "2",
            "package": "/patch_2.zip"
        },
        {
            "js_vs": "1",
            "package": "/patch_1.zip"
        }
    ]
}

android 原生部分,网络请求

interface IHttpResponse {
    fun onFailed(s: String?, type: String)

    fun onResult(s: String?, type: String)

    fun onSocketFailed()

    fun onFailedConnect()
    fun onFailed()
}

class OkReq(private val response: IHttpResponse) {

    val gson = Gson()

    fun getSimple(url: String, type: String) {
        val request = Request.Builder()
                .url(url)
                .get()
                .build()
        val newCall = OkClients.okHttpClient.newCall(request)
        simpleCallback(newCall, type)
    }

    private fun simpleCallback(newCall: Call, type: String) {
        launch(CommonPool) {
            try {
                val response = newCall.execute()
                val string = response.body()?.string()
                string?.let { launch(UI) { [email protected](it, type) } }
            } catch (e: Exception) {
                e.printStackTrace()
                launch(UI) {
                    [email protected](e.message, type)
                }
            }
        }
    }
}

然后我们去获取json,http://localhost:8080/version
这里写图片描述
现在我们要处理的问题
1.是获取安卓的版本然后强制更新,因为后台喜欢随意改接口
2.获取sp中的js版本
3.根据版本号去判断这个是不是需要下载,如果超过两个包那么就直接重新下个全量的包。如果小于2那么就一个个的更新。
话不多说我先写写
正在更新中
to be continue

Debian / Ubuntu:

apt-get install git
git clone https://github.com/shadowsocksr/shadowsocksr.git

CentOS:

yum install git
git clone https://github.com/shadowsocksr/shadowsocksr.git

Windows:

git clone https://github.com/shadowsocksr/shadowsocksr.git

Usage for single user on linux platform

If you clone it into “~/shadowsocksr”
move to “~/shadowsocksr”, then run:

bash initcfg.sh

move to “~/shadowsocksr/shadowsocks”, then run:

python server.py -p 443 -k password -m aes-128-cfb -O auth_aes128_md5 -o tls1.2_ticket_auth_compatible

Check all the options via -h.

You can also use a configuration file instead (recommend), move to “~/shadowsocksr” and edit the file “user-config.json”, then move to “~/shadowsocksr/shadowsocks” again, just run:

python server.py

To run in the background:

./logrun.sh

To stop:

./stop.sh

To monitor the log:

./tail.sh

Client

Use GUI clients on your local PC/phones. Check the README of your client
for more information.

Documentation

You can find all the documentation in the Wiki.

License

Copyright 2015 clowwindy

Licensed under the Apache License, Version 2.0 (the “License”); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

Bugs and Issues

猜你喜欢

转载自blog.csdn.net/arios171/article/details/81026924
今日推荐