How to install interpreter for SL4A in offline

最后都变了- 提交于 2019-12-25 08:59:55

问题


I'm really interested in android scripting on perl/python/lua at my current job, but I'm also very limited in traffic consumption and I may need frequently repeat interpreters install procedure after reflashing android devices. So is there any way to install interpreters in SL4A using prepared files/archives without internet connection?


回答1:


For installing Py4a, I ended up modifying android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java, changing BASE_URL there into a file:/// URL. I was then able to adb push the python_*.zip files into that directory, and install from there.

A key was paying attention to the logcat error messages. As I had no version files, the code asked for an _r1.zip always.

Apply the following patch, and then just follow the instructions in the README file of Py4A to build the APK.

diff --git a/android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java b/android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java
index a891e98..89bb4f7 100644
--- a/android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java
+++ b/android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java
@@ -39,7 +39,7 @@ public class PythonDescriptor extends Sl4aHostedInterpreter {
   public static final String ENV_EXTRAS = "PY4A_EXTRAS";
   public static final String ENV_EGGS = "PYTHON_EGG_CACHE";
   public static final String ENV_USERBASE = "PYTHONUSERBASE";
-  public static final String BASE_URL = "http://python-for-android.googlecode.com/";
+  public static final String BASE_URL = "file:///data/data/tmp/";
   private static final int LATEST_VERSION = -1;
   private int cache_version = -1;
   private int cache_extras_version = -1;

Once you have the .apk, go ahead and install everything:

pushd android/PythonForAndroid
adb install -r bin/PythonForAndroid-debug.apk
popd

pushd python-build
adb shell mkdir -p /data/data/tmp/files
adb push python_r16.zip /data/data/tmp/files/python_r-1.zip
adb push python_extras_r14.zip /data/data/tmp/files/python_extras_r-1.zip
adb push python_scripts_r13.zip /data/data/tmp/files/python_scripts_r-1.zip
popd

The final step is to launch Py4A, and poke Install.




回答2:


The straightforward way that I found is to install everything in online mode once, then compress the contents of directories:

/data/data/com.googlecode.{language}forandroid,
/sdcard/com.googlecode.{language}forandroid,
/sdcard/sl4a

And make any subsequent install using following batch script (Windows)

set ADB_BIN="C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe"
%ADB_BIN% install -r sl4a_r4.apk
%ADB_BIN% install -r PythonForAndroid_r4.apk
%ADB_BIN% install -r perl_for_android_r1.apk
%ADB_BIN% install -r lua_for_android_r1.apk

%ADB_BIN% push sd.tgz /sdcard/
%ADB_BIN% shell busybox tar -xzf /sdcard/sd.tgz -C /sdcard
%ADB_BIN% push data.tgz /sdcard/
%ADB_BIN% root
%ADB_BIN% remount
%ADB_BIN% shell busybox tar -xzf /sdcard/data.tgz -C /data/data

%ADB_BIN% shell rm /sdcard/sd.tgz
%ADB_BIN% shell rm /sdcard/data.tgz


来源:https://stackoverflow.com/questions/8850640/how-to-install-interpreter-for-sl4a-in-offline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!