Android gradle packaging and automatic uploading method
brief introduction
This article mainly introduces that Android is packaged with gradle, and calls Python script to upload the packaged APK to fir.im for relevant personnel to download. It is helpful for learning gradle packaging and several common network libraries of Python
Keyword: Android gradle Python fir.im
1 preparation before development
Before development, you need to download Android studio, gradle (version 3.3), python 3.6, curl and pycurl
Prepare a fir.im account with apitoken corresponding to the account. For details of the specific fir.im, please refer to the document fir.im
The development environment is MacOS. Windows recommends replacing all pycurl parts with requests, that is, the way to upload APK codes instead of uploading icons. See the code for details
2 gradle scripting
What we need to do in the script is to pass the APK path to the python script after the APK is packaged. How to ensure that the package is packaged, we can use gradle's dependson method. For example, by opening the debug package, we can write a task. This task dependson 'assemblydebug', so that when the task is called, it will execute assemblydebug first, and then execute the code in it, That is, the specific code that meets our needs
3. Preparation of Python script
This Python script has a little learning content, so it uses three network request libraries: urllib, requests and pycurl. In fact, it only needs one. The key here is to understand the request format and response of fir.im upload. For details, please refer to the document fir.im, which mainly transmits the APK identification information and the user's apitoken to fir.im, which will respond to the file upload address and icon upload address, and then transfer the corresponding file and information to the return address, Finally, you can query the corresponding download page of APK on fir.im through the identification information of APK and the user's apitoken
Then let's talk about the three steps of installation
3.1 query upload address
The official documents are as follows
So write the python 3 code according to the document as follows
3.2 upload icon and apk
The path was obtained before, and then the file was transmitted. Note that Python 3 has a hole in the request for HTTPS. If the code reports SSL error, execute Python 3 according to the install certificates.command file in the directory. For the path, refer to / applications / Python 3.6/certificates.command. The official document is as follows. For details, please refer to the official website
So the corresponding py script is as follows
3.3 obtain the download page of APK file
After the APK is uploaded, a download sharing page will be generated. You can get the official documents directly through the get request
We use the bundle_ ID, this bundleid is the name passed in by gradle and the returned update_ URL is the page sharing APK
So the PY code is as follows
The complete py code is as follows
That's good
Execute the code gradle assemblywithlog in the project corresponding to Android studio
Start to package debug and upload it to fir.im
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.