使用JavaScript和PHP开发原生Android应用 [英] Using javascript and PHP to develop native android apps

查看:303
本文介绍了使用JavaScript和PHP开发原生Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我对这个问题的含糊道歉,但它是什么我希望你可以清理我。

First off, I apologise for the ambiguity of this question but it is something I am hoping you can clear up for me.

这个概念是,我会用Java编写的一个应用一个predefined模板,该模板将包括类如:

The concept is that I would have a predefined template written in Java for an app, the template would consist of Classes such as:

public class Image {  

    private int _x;  
    private int _y;

    Image() {  
        _x = 0;  
        _y = 0;  
    }  

    Image(Int x, Int y) {  
        _x = x;  
        _y = y;  
    }  
}

下位我知道如何做到这是使用JavaScript来数据发布到PHP,但后来我想PHP来使用这些数据来构建Java应用程序。例如。我可能有一个PHP函数的createImage($ X = 0,$ Y = 0),那么这将添加到Java源(PHP将必须通过变量名。等):

The next bit I understand how to accomplish which is using javascript to post data to PHP, but I then want PHP to use this data to build the Java app. E.g. I might have a PHP function createImage($x = 0, $y = 0), which would then add to the Java source (The PHP would have to pass variable names.etc):

Image image342 = new Image(x, y);

我稍后要编译到一个.apk文件android应用。

Which I will later want to compile to an .apk android application.

我无法工作如何让PHP来修改和添加到Java源代码,我知道我可以用绳子做到这一点,并写入到一个物理文件.e.g

I am having trouble working out how to get PHP to modify and add to the Java source, I realise I could do this with strings and writing to a physical file .e.g

public function createImage ($x = 0, $y = 0) {
  $this->$num++;
  $string = "Image image{$this->$num} = new Image({$x}, {$y});";
  $handle = fopen("/java/source/file", "ab");
  fwrite($handle, $string);
  fclose($handle);
}

但这种感觉有点乱了,我想知道是否有更好的方式来实现我的任务。

But this feels somewhat messy, and I'm wondering if there is a better way to achieve my task.

感谢

推荐答案

考虑到整个Android构建链(如编译器, DX 字节code交叉编译器)需要的文件,你没有选择,只能创建文件。创建项目的价值基于模板的自定义文件是code一代的一个相当典型的形式。例如,当您从Eclipse的向导创建新的Andr​​oid项目,这是pretty多少它做什么。

Considering that the entire Android build chain (e.g., compiler, dx bytecode cross-compiler) needs files, you have no choice but to create files. Creating a project's worth of customized files based on templates is a fairly typical form of code generation. For example, when you create a new Android project from the Eclipse wizard, that's pretty much what it does.

这code一代人会以创建Android项目的Ant构建脚本(根据您从 Android的创建项目命令,在一个) 。你的服务器可以再code根则项目并创建一个进程运行Ant给你APK。

Part of that code generation would be to create an Ant build script for the Android project (based on the one you get from the android create project command). Your server could then code-gen then project and fork a process to run Ant to give you the APK.

无论PHP是您code-生成问题与使用别的东西已经做了目录的价值的文件的模板驱动的新一代的解决方案,我不能说。

Whether PHP is the right solution for your code-generation problem versus using something else that already does template-driven generation of a directory's worth of files, I can't say.

这篇关于使用JavaScript和PHP开发原生Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆