如何通过.apk传递dalvik命令行参数?

时间:2022-08-24 12:21:16

I know that it is possible to launch java program in Android in a such way:

我知道有可能以这种方式在Android中启动java程序:

adb push "hello_world.zip" $REMOTE_PATH/
adb shell mkdir $REMOTE_PATH/dalvik-cache
adb shell dalvikvm -cp "$REMOTE_PATH/hello_world.zip" -Xint:portable -Xdexopt:none -Xverify:none hello_world

It's very good!

这很好!

But now I want to create Android .apk file. And I want this application to be launched with the same command line parameters "-Xint:portable -Xdexopt:none -Xverify:none" automatically.

但现在我想创建Android .apk文件。我希望这个应用程序能够使用相同的命令行参数“-Xint:portable -Xdexopt:none -Xverify:none”自动启动。

I assume that parameters names may differ from this "-Xint:portable -Xdexopt:none -Xverify:none", but functionality must be the same. I have no idea what I have to do and google doesn't want to help me to solve this issue. Any help would be much appreciated!

我假设参数名称可能与此“-Xint:portable -Xdexopt:none -Xverify:none”不同,但功能必须相同。我不知道我要做什么,谷歌不想帮我解决这个问题。任何帮助将非常感激!

2 个解决方案

#1


2  

I'm reasonably certain that you can't. You can change the system-wide interpreter mode with setprop dalvik.vm.execution-mode int:portable but you would need root. I don't know of any way to disable dexopt for your process only (that would be a security risk!). You most certainly can't touch the bootclasspath (which is the classpath that your app initially runs under).

我有理由相信你做不到。您可以使用setprop dalvik.vm.execution-mode int:portable更改系统范围的解释器模式,但您需要root。我不知道有什么办法只为你的进程禁用dexopt(这会带来安全风险!)。你肯定无法触及bootclasspath(这是你的app最初运行的类路径)。

I believe you can disable jnicheck for your process but that's about it.

我相信你可以为你的过程禁用jnicheck但这就是它。

Apps on the device run via app_process and the zygote, you can think of them as restricted wrappers around Dalvik. There are no dalvikvm invocations apart from the initial zygote one - every future process starts with a fork(), so you can't actually change those parameters without messing with the zygote. (I'm simplifying but I'm pretty sure I'm right)

设备上的应用程序通过app_process和zygote运行,您可以将它们视为Dalvik周围的限制包装器。除了最初的zygote之外,没有dalvikvm调用 - 每个未来的进程都以fork()开头,所以你不能在不弄乱zygote的情况下实际更改这些参数。 (我正在简化,但我很确定我是对的)

#2


3  

I think @Delyan's answer hit the important points, but I wanted to add a few more details that didn't fit in a comment.

我认为@ Delyan的答案达到了重点,但我想补充一些不符合评论的细节。

The official doc on doing this sort of thing is Controlling the Embedded VM (in source tree). The execution-mode property affects all apps, because the VM is only started once -- as "zygote" -- and all apps are launched by forking that process.

执行此类操作的官方文档是控制嵌入式VM(在源代码树中)。执行模式属性会影响所有应用程序,因为VM仅启动一次 - 作为“zygote” - 并且所有应用程序都是通过分叉该进程启动的。

It's possible to change the mode of the VM once it has started, perhaps by introducing a new VMRuntime API call, but I don't think anybody has tried that and I'm not sure offhand how it would interact with the JIT compiler.

可能会在VM启动后更改VM的模式,可能是通过引入新的VMRuntime API调用,但我认为没有人尝试过,我不确定它是如何与JIT编译器进行交互的。

Most DEX optimization and verification is performed by dexopt before the app is ever launched, and the results are stored in the .odex file in /data/dalvik-cache, so tweaking -Xdexopt and -Xverify at app launch time may not do much (see dexopt docs; source).

大多数DEX优化和验证是在应用程序启动之前由dexopt执行的,结果存储在/ data / dalvik-cache中的.odex文件中,因此在应用程序启动时调整-Xdexopt和-Xverify可能不会做太多(请参阅dexopt docs; source)。

#1


2  

I'm reasonably certain that you can't. You can change the system-wide interpreter mode with setprop dalvik.vm.execution-mode int:portable but you would need root. I don't know of any way to disable dexopt for your process only (that would be a security risk!). You most certainly can't touch the bootclasspath (which is the classpath that your app initially runs under).

我有理由相信你做不到。您可以使用setprop dalvik.vm.execution-mode int:portable更改系统范围的解释器模式,但您需要root。我不知道有什么办法只为你的进程禁用dexopt(这会带来安全风险!)。你肯定无法触及bootclasspath(这是你的app最初运行的类路径)。

I believe you can disable jnicheck for your process but that's about it.

我相信你可以为你的过程禁用jnicheck但这就是它。

Apps on the device run via app_process and the zygote, you can think of them as restricted wrappers around Dalvik. There are no dalvikvm invocations apart from the initial zygote one - every future process starts with a fork(), so you can't actually change those parameters without messing with the zygote. (I'm simplifying but I'm pretty sure I'm right)

设备上的应用程序通过app_process和zygote运行,您可以将它们视为Dalvik周围的限制包装器。除了最初的zygote之外,没有dalvikvm调用 - 每个未来的进程都以fork()开头,所以你不能在不弄乱zygote的情况下实际更改这些参数。 (我正在简化,但我很确定我是对的)

#2


3  

I think @Delyan's answer hit the important points, but I wanted to add a few more details that didn't fit in a comment.

我认为@ Delyan的答案达到了重点,但我想补充一些不符合评论的细节。

The official doc on doing this sort of thing is Controlling the Embedded VM (in source tree). The execution-mode property affects all apps, because the VM is only started once -- as "zygote" -- and all apps are launched by forking that process.

执行此类操作的官方文档是控制嵌入式VM(在源代码树中)。执行模式属性会影响所有应用程序,因为VM仅启动一次 - 作为“zygote” - 并且所有应用程序都是通过分叉该进程启动的。

It's possible to change the mode of the VM once it has started, perhaps by introducing a new VMRuntime API call, but I don't think anybody has tried that and I'm not sure offhand how it would interact with the JIT compiler.

可能会在VM启动后更改VM的模式,可能是通过引入新的VMRuntime API调用,但我认为没有人尝试过,我不确定它是如何与JIT编译器进行交互的。

Most DEX optimization and verification is performed by dexopt before the app is ever launched, and the results are stored in the .odex file in /data/dalvik-cache, so tweaking -Xdexopt and -Xverify at app launch time may not do much (see dexopt docs; source).

大多数DEX优化和验证是在应用程序启动之前由dexopt执行的,结果存储在/ data / dalvik-cache中的.odex文件中,因此在应用程序启动时调整-Xdexopt和-Xverify可能不会做太多(请参阅dexopt docs; source)。