如何在我的Android应用程序中集成Python脚本(比如SL4A)

时间:2022-05-07 20:47:24

I need to add scripting layer to my android App. So I can remotely prepare a script that my app download form a web service and execute on the user device.

我需要将脚本层添加到我的android应用程序中,这样我就可以远程准备一个脚本,让我的应用程序从web服务中下载并在用户设备上执行。

I found a interesting project called Scripting Layer for Android (SL4A) here:

我在这里发现了一个有趣的项目,叫做Android脚本层(SL4A):

http://code.google.com/p/android-scripting/

http://code.google.com/p/android-scripting/

I'm not sure I can execute Python script without installing the PythonForAndroid_r4.apk first. I can't force my customer to install that application!

我不确定是否可以在不安装PythonForAndroid_r4的情况下执行Python脚本。apk第一。我不能强迫我的客户安装那个应用程序!

So my question is, can the SL4A layer be integrated in my app without the need to install other apk?

所以我的问题是,SL4A层是否可以集成到我的app中而不需要安装其他apk?

I need to execute actions like update data in the DB, create/read/delete a file on the sd card... Not so complex but I see SL4A can do a lot of things like these.

我需要执行一些操作,比如在DB中更新数据,在sd卡上创建/读取/删除文件……不是很复杂,但是我看到SL4A可以做很多这样的事情。

Other scripting libraries?

其他脚本库吗?

EDIT: Found also MVEL: http://mvel.codehaus.org/ but I think it needs to be integrated to execute complex operations like accessing a DB...

编辑:还可以找到MVEL: http://mvel.codehaus.org/,但是我认为需要集成它来执行复杂的操作,比如访问DB…

1 个解决方案

#1


5  

I found a project that uses SL4A:

我发现了一个使用SL4A的项目:

http://code.google.com/p/android-python27/

http://code.google.com/p/android-python27/

For whom that wants to try it, if error occurs using Eclipse, here is a link that could solve the compilation issue:

对于想要尝试它的人,如果使用Eclipse发生错误,这里有一个可以解决编译问题的链接:

http://code.google.com/p/android-python27/issues/detail?id=1

http://code.google.com/p/android-python27/issues/detail?id=1

I've just compiled this project:

我刚刚编译了这个项目:

http://code.google.com/p/android-python27/source/browse/#hg%2Fapk

http://code.google.com/p/android-python27/source/browse/ hg fapk % 2

To download sources, download HG Tortoise from:

下载资源,下载HG乌龟:

http://tortoisehg.bitbucket.io/download/

http://tortoisehg.bitbucket.io/download/

Make a local copy of the repository with the command:

使用以下命令制作存储库的本地副本:

hg clone https://code.google.com/p/android-python27/ 

Then import the APK project in Eclipse and compile it.

然后在Eclipse中导入APK项目并编译它。

Just run it on my low cost China tablet and it seems to works fine. Initially the program make an installation:

只要在我的低成本的中国平板电脑上运行它,它似乎运行良好。最初程序进行安装:

boolean installNeeded = isInstallNeeded();

if(installNeeded) {
  setContentView(R.layout.install); 
  new InstallAsyncTask().execute();
}

That make some installations on the external storage (fortunately no root privileges are needed).

这使得在外部存储上进行一些安装(幸运的是不需要root特权)。

#1


5  

I found a project that uses SL4A:

我发现了一个使用SL4A的项目:

http://code.google.com/p/android-python27/

http://code.google.com/p/android-python27/

For whom that wants to try it, if error occurs using Eclipse, here is a link that could solve the compilation issue:

对于想要尝试它的人,如果使用Eclipse发生错误,这里有一个可以解决编译问题的链接:

http://code.google.com/p/android-python27/issues/detail?id=1

http://code.google.com/p/android-python27/issues/detail?id=1

I've just compiled this project:

我刚刚编译了这个项目:

http://code.google.com/p/android-python27/source/browse/#hg%2Fapk

http://code.google.com/p/android-python27/source/browse/ hg fapk % 2

To download sources, download HG Tortoise from:

下载资源,下载HG乌龟:

http://tortoisehg.bitbucket.io/download/

http://tortoisehg.bitbucket.io/download/

Make a local copy of the repository with the command:

使用以下命令制作存储库的本地副本:

hg clone https://code.google.com/p/android-python27/ 

Then import the APK project in Eclipse and compile it.

然后在Eclipse中导入APK项目并编译它。

Just run it on my low cost China tablet and it seems to works fine. Initially the program make an installation:

只要在我的低成本的中国平板电脑上运行它,它似乎运行良好。最初程序进行安装:

boolean installNeeded = isInstallNeeded();

if(installNeeded) {
  setContentView(R.layout.install); 
  new InstallAsyncTask().execute();
}

That make some installations on the external storage (fortunately no root privileges are needed).

这使得在外部存储上进行一些安装(幸运的是不需要root特权)。