0
使用ASM注射一類的所有方法執行失敗的任務「:應用程序:transformClassesWithDexForDebug」返回代碼1 DEX過程
這裏是我的代碼:
變換API獲得所有類
def cacheFile = new File(file.parent, file.name + ".cache");
fis = new FileInputStream(file)
fos = new FileOutputStream(cacheFile)
println "injectFile: ${file.path}"
byte[] bytes = hackClass(file, null, false, fis);
fos.write(bytes)
if (file.exists()) {
file.delete()
}
cacheFile.renameTo(file)
ASM方法位訪問者
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = null;
if(name.equals("onCreate") || name.equals("onPause")){
System.out.println(file.getName() + "Method name : " + name);
mv = cv.visitMethod(access, name, desc, signature, exceptions);
return new TraceMethodVisitor(name, mv);
}
if (cv != null){
mv = cv.visitMethod(access, name, desc, signature, exceptions);
}
return mv;
}
MethodVisitor中的代碼:
@Override
public void visitCode() {
//add start
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("========start=========");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
mv.visitLdcInsn("Hi");
mv.visitLdcInsn("hello world");
mv.visitMethodInsn(INVOKEVIRTUAL, "android/util/Log", "v", "(Ljava/lang/String;Ljava/lang/String;)I", false);
super.visitCode();
}
如果MethodVisitor中只需要修改一個方法中,成功
修改兩個或更多個方法,失敗,上述代碼修改兩種方法
下面是從控制檯輸出:
:app:transformClassesWithDexForDebug
Uncaught translation error: com.android.dx.cf.code.SimException:stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException:stack: overflow
2 errors; aborting
:app:transformClassesWithDexForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
我該如何解決這個問題? :(
附加multiDexEnabled在建的默認配置文件屬實。這樣的gradle 'defaultConfig { multiDexEnabled true }' 並且可以添加編譯文件: 編譯'com.android.support:multidex:1.0.1' – ashish
無用,也許轉換不能使用multidex,新錯誤:執行任務':app:transformClassesWithMultidexlistForDebug'失敗。 > proguard.KeepClassSpecification。(ZZZZZZLproguard/ClassSpecification;)V –