https://www.jianshu.com/p/6e516fe0cccd
1.下载apktool,我用的是apktool_2.1.1.jar。
2.需要拆包的apk。
用到的命令:
解包:
java -jar apktool_2.1.1.jar d app-test.apk
打包:
java -jar apktool_2.1.1.jar b app-test/
签名:
jarsigner -verbose -keystore moonlighting.jks(证书) -storepass [密钥] -keypass [密钥] -signedjar Thinkdrive_signed.apk(签名完后的apk) app-test/dist/app-debug.apk(上一步中产生的apk) moonlighting(证书名)
1.打开Terminal,进入apktool的工作路径:
image
执行命令:java -jar apktool_2.1.1.jar d app-test.apk
image
操作成功后会产生一个与apk文件名相同的一个文件夹,结构如下:
image
从上图文件结构可以看到。所有的xml文件都是可以在这里找到的,资源文件在名为res的文件下,而且没有变化。而之前的java代码在这里变成了.smali文件在名为smali的文件夹中。
1.(简单修改)因为资源文件没有变化,可以直接修改,比如修改一些字符串的对应值,样式、颜色等。布局文件也没有变化,可以直接对布局中的控件的位置、长宽、背景颜色等直接做修改。
2.(加入新的页面)举个例子,我现在要在当前程序再加一个前导页:
image
package com.mrtian.project.launcherapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class LauncherActivity extends Activity {
private TextView textView;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
textView = (TextView) findViewById(R.id.zz_tv_main);
button = (Button) findViewById(R.id.zz_btn_start);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("start!!!");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent("com.parttime.happytime.start");
startActivity(intent);
}
},6000);
}
});
}
}
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mrtian.project.launcherapplication.LauncherActivity">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
将前导页工程编译产生apk,用一种同样的方法解包:
image
image
ids.xml:
image
public.xml:
值得一说的是public.xml内部的id值是16进制数编号,我们只需要在对应的type最后按顺序添加就可以了。
image
image
image
因为smali文件都是之前产生的,合并到本工程时id需要改为现在修改的id:
在目录里面找到LauncherActivity.smali文件并打开,
所有资源的id对需要改为刚才我们在public.xml中给资源添加的id值:
布局:
image
控件:
image
image
如果需要const/high16这样的声明,指的是对这个id值舍入,修改id值时将其改成const就行了,否则之后打包会报错
经过上面的步骤,我们的工程算是合并完了,打开终端,输入命令:
java -jar apktool_2.1.1.jar b app-test/
成功执行后会在app-test/dist目录下产生一个apk
在对该apk进行签名操作:
jarsigner -verbose -keystore moonlighting.jks(证书) -storepass [密钥] -keypass [密钥] -signedjar Thinkdrive_signed.apk(签名完后的apk) app-test/dist/app-debug.apk(上一步中产生的apk) moonlighting(证书名)
作者:寻找密码
链接:https://www.jianshu.com/p/6e516fe0cccd
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。