如何在离线状态下为SL4A安装解释器

时间:2012-01-13 12:31:56

标签: android installation sl4a

我真的对perl / python / lua上的android脚本感兴趣,但是我的流量消耗非常有限,我可能需要在重新刷新android设备后经常重复解释器安装程序。那么有没有办法在没有互联网连接的情况下使用准备好的文件/档案在SL4A中安装解释器?

2 个答案:

答案 0 :(得分:1)

为了安装Py4a,我最终修改了android/PythonForAndroid/src/com/googlecode/pythonforandroid/PythonDescriptor.java,将BASE_URL更改为file:///网址。然后我能够将adb pushpython_*.zip个文件放到该目录中,然后从那里安装。

关键是要关注logcat错误消息。由于我没有版本文件,因此代码始终要求_r1.zip

应用以下补丁,然后按照Py4A的README文件中的说明构建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;

获得.apk后,请继续安装所有内容:

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

最后一步是启动Py4A,然后戳Install

答案 1 :(得分:0)

我找到的简单方法是在线模式安装一次,然后压缩目录的内容:

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

使用以下批处理脚本(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