안드로이드 다중 채널 패키지 도구를 직접 쓰면libs와.so 파일
패키지 도구 종류를 공유합니다.인터넷에도 비슷한 것이 있다. 나는 그것을 바탕으로 최적화를 했다. 특히 so 파일을 포장했는데 작은 명령 한 마디가 많이 폐기되었다.
우리 프로젝트에서 사용하는umeng은 통계 분석 도구를 만들고umeng은 채널을 나누어 포장할 때 manifest를 수정해야 한다.xml의
이 값은strings에 넣었습니다.xml에서
다음은 공구류입니다. 직접 운행하면 됩니다.
package com.yang.main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* @description: android , , channels
* @author: [email protected]
* @time: 2012-10-23 5:17:47
*/
public class CompiledApkUpdate {
private static final String androidSDK_PATH = "D:\\android\\android-sdk-windows\\"; //android SDK
public static final String APK_NAME = "duitang.apk";
public static final String PROJECT_LIBARY = "";
public static final String PROJECT_PATH = "D:\\android\\workspace\\tmp\\duitang\\"; //
public static final String APK_PATH = "D:\\android\\workspace\\tmp\\apk\\duitang_"; // apk duitang_
private static final String apk_PATH_keystore = "D:\\android\\keystore\\bb"; //apk
private static final String channelFlag = "app_channel";
// public static String[] channels = {"duitang"};
private static String currentChannelName = "";
public static String[] channels = {"duitang","91","360","QQ","jifeng","anzhuo","anzhi","youyi","appchina","wangyi","baidu","souhu","3g","nduo","xiaomi","huawei","meizu","lianxiang","aliyun","taobao","google","nearme","mumayi","wandoujia","crosscat","dangle","maopao","feiliu"};
public static void main(String[] args) {
replaceChannel();
}
/**
*
*/
public static void replaceChannel() {
try {
String outPath = PROJECT_PATH + "res\\values\\strings.xml"; //
String content = read(outPath);
for(int channelid=0;channelid<channels.length;channelid++){
String tmpContent = content;
tmpContent = tmpContent.replaceFirst(channelFlag, channels[channelid]);
currentChannelName = channels[channelid];
write(tmpContent,outPath);
System.out.println("replace channel name over...");
packageRes(); // 。 。
createUnsignedApk();
signedApk(channelid);
}
write(content,outPath); // channel_name
System.out.println("execute over!");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* class classes.dex
*/
public static void packageDex(){
try {
System.out.println("dx.bat start...");
Process process = Runtime.getRuntime().exec(androidSDK_PATH
+"platform-tools\\dx.bat --dex --output="
+PROJECT_PATH+"bin\\classes.dex "
+PROJECT_PATH+"bin\\classes "
+PROJECT_PATH+"libs\\*.jar");
new MyThread(process.getErrorStream()).start();
new MyThread(process.getInputStream()).start();
process.waitFor();
process.destroy();
System.out.println("dx.bat over...");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* res assets res.zip
*/
public static void packageRes(){
try{
System.out.println(currentChannelName+" create resources.ap");
String library = "";
if(PROJECT_LIBARY!=null&&!PROJECT_LIBARY.equals("")){
library = "-S " + PROJECT_LIBARY + "res ";
}
Process process = null;
process = Runtime
.getRuntime()
.exec( androidSDK_PATH
+ "platform-tools\\aapt.exe package -f " +
"-M " + PROJECT_PATH + "AndroidManifest.xml " + //-M
"-S " + PROJECT_PATH + "res " + //-S
library +
"-A " + PROJECT_PATH + "assets " + //-A assets
"-I " + androidSDK_PATH + "platforms\\android-16\\android.jar " + //-I android
"-F " + PROJECT_PATH + "bin\\resources.ap_ --auto-add-overlay"); // resources.ap_
new MyThread(process.getErrorStream()).start();
new MyThread(process.getInputStream()).start();
process.waitFor();
process.destroy();
System.out.println(currentChannelName+" resources.ap over...");
}catch(Exception e){
e.printStackTrace();
}
}
/**
* classes.dex res.zip AndroidManifest.xml apk
*/
public static void createUnsignedApk(){
try{
System.out.println(currentChannelName+" createUnsignedApk start");
Process process = null;
process = Runtime.getRuntime().exec(
androidSDK_PATH+ "tools\\apkbuilder.bat "
+ PROJECT_PATH + "bin\\"+APK_NAME+" -u -z "
+ PROJECT_PATH + "bin\\resources.ap_ -f "
+ PROJECT_PATH + "bin\\classes.dex"
+" -rj "+ PROJECT_PATH + "libs" // libs jar
+" -nf "+ PROJECT_PATH + "libs" // , 。 so 。
); // apk.
new MyThread(process.getErrorStream()).start();
new MyThread(process.getErrorStream()).start();
process.waitFor();
process.destroy();
System.out.println(currentChannelName+" createUnsignedApk over");
}catch(Exception e){
e.printStackTrace();
}
}
/**
* apk
*/
public static void signedApk(int channelid){
try{
System.out.println(currentChannelName+" signed apk start");
Process process = null;
String jarsigner;
jarsigner = "jarsigner -keystore "+apk_PATH_keystore+" -storepass ***** -keypass ****** " +
"-signedjar "
+ APK_PATH
+ channels[channelid]
+ ".apk "
+ PROJECT_PATH
+ "bin\\"+APK_NAME+" *****"; // apk
process = Runtime
.getRuntime()
.exec(jarsigner); // apk
new MyThread(process.getErrorStream()).start();
new MyThread(process.getInputStream()).start();
process.waitFor();
process.destroy();
System.out.println(currentChannelName+" signed apk over"); // 。
}catch(Exception e){
e.printStackTrace();
}
}
/**
* google 。 zipalign apk
*/
public static void zipalignApk(int channelid){
try{
System.out.println(currentChannelName+":zipalign apk start");
String apkPath=APK_PATH.replace("{c}", channels[channelid]);
File file=new File(apkPath);
if(!file.getParentFile().isDirectory()) file.getParentFile().mkdirs();
Process process = null;
String jarsigner;
jarsigner = "cmd.exe /C "+androidSDK_PATH+"tools/zipalign.exe -v 4 "
+ apkPath
+ ".apk "
+ apkPath
+ "-z.apk"; // apk
process = Runtime
.getRuntime()
.exec(jarsigner); // apk
new MyThread(process.getErrorStream()).start();
new MyThread(process.getInputStream()).start();
process.waitFor();
process.destroy();
System.out.println(currentChannelName+":zipalign apk over"); // 。
}catch(Exception e){
e.printStackTrace();
System.exit(0);
}
}
public static String read(String path) {
StringBuffer res = new StringBuffer();
String line = null;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path),"UTF-8"));
while ((line = reader.readLine()) != null) {
res.append(line + "
");
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return res.toString();
}
public static boolean write(String cont, String dist) {
try {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(dist)),"utf-8");
writer.write(cont);
writer.flush();
writer.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static class MyThread extends Thread{
BufferedReader bf;
public MyThread(InputStream input) {
bf = new BufferedReader(new InputStreamReader(input));
}
public void run() {
String line;
try {
line = bf.readLine();
while (line != null) {
System.out.println(line);
line = bf.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.