|
| 1 | +package nl.tudelft.selfcompileapp; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStream; |
| 6 | +import java.io.PrintWriter; |
| 7 | + |
| 8 | +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; |
| 9 | +import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler; |
| 10 | + |
| 11 | +import android.app.Activity; |
| 12 | +import android.os.AsyncTask; |
| 13 | +import android.os.Bundle; |
| 14 | +import android.os.Environment; |
| 15 | +import android.view.View; |
| 16 | +import android.widget.Button; |
| 17 | + |
| 18 | +public class MainActivity extends Activity { |
| 19 | + |
| 20 | + @Override |
| 21 | + protected void onCreate(Bundle savedInstanceState) { |
| 22 | + super.onCreate(savedInstanceState); |
| 23 | + setContentView(R.layout.activity_main); |
| 24 | + } |
| 25 | + |
| 26 | + void toggleBtnCompile(boolean enabled) { |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + public void selfCompile(View btnCompile) { |
| 31 | + btnCompile.setEnabled(false); |
| 32 | + new CompilePrjSrc().execute(); |
| 33 | + } |
| 34 | + |
| 35 | + private class CompilePrjSrc extends AsyncTask<Object, Object, Object> { |
| 36 | + |
| 37 | + @Override |
| 38 | + protected void onPostExecute(Object result) { |
| 39 | + Button btnCompile = (Button) findViewById(R.id.btnCompile); |
| 40 | + btnCompile.setEnabled(true); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected Object doInBackground(Object... params) { |
| 45 | + try { |
| 46 | + System.out.println("// CLEAR OUTPUT FOLDER"); |
| 47 | + File dirDownloads = Environment |
| 48 | + .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); |
| 49 | + File dirProject = new File(dirDownloads, "demo_android"); |
| 50 | + Util.deleteRecursive(dirProject); |
| 51 | + |
| 52 | + System.out.println("// COPY PROJECT SOURCE"); |
| 53 | + InputStream zipPrjSrc = getAssets().open("demo_android.zip"); |
| 54 | + Util.unZip(zipPrjSrc, dirDownloads); |
| 55 | + |
| 56 | + System.out.println("// COPY ANDROID PLATFORM"); |
| 57 | + InputStream zipAndroidPlatform = getAssets().open( |
| 58 | + "android-22.zip"); |
| 59 | + Util.unZip(zipAndroidPlatform, dirDownloads); |
| 60 | + |
| 61 | + // TODO REMOVE R.JAVA |
| 62 | + |
| 63 | + // TODO RUN AAPT & CREATE R.JAVA |
| 64 | + File dirGen = new File(dirProject, "gen"); |
| 65 | + dirGen.mkdir(); |
| 66 | + |
| 67 | + System.out.println("// COMPILE SOURCE RECURSIVE"); |
| 68 | + |
| 69 | + // -verbose |
| 70 | + // -deprecation |
| 71 | + // -extdirs \"\" |
| 72 | + // -1.5 |
| 73 | + // -bootclasspath |
| 74 | + // {AndroidJarPath}: |
| 75 | + // {root}libs/ecj.jar: |
| 76 | + // {root}libs/dx_ta.jar: |
| 77 | + // {root}libs/bsh.jar: |
| 78 | + // {root}libs/sdklib_ta.jar: |
| 79 | + // {root}libs/androidprefs.jar: |
| 80 | + // {root}libs/zipsigner-lib_all.jar |
| 81 | + // -classpath |
| 82 | + // {root}src: |
| 83 | + // {root}gen |
| 84 | + // -d {stScriptPath}bin |
| 85 | + // {root}src/com/t_arn/MainActivity.java |
| 86 | + |
| 87 | + String strRoot = dirDownloads.getAbsolutePath(); |
| 88 | + String strProj = dirProject.getAbsolutePath(); |
| 89 | + String strArgs = " -verbose -1.5"; |
| 90 | + strArgs += " -bootclasspath \"" + strRoot + "/android-22.jar:" |
| 91 | + + strRoot + "/android-support-v13.jar:" + strRoot |
| 92 | + + "/android-support-annotations.jar\""; |
| 93 | + strArgs += " -cp \"" + strProj + "/libs/demolib.jar:" + strProj |
| 94 | + + "/src:" + strProj + "/gen\""; |
| 95 | + strArgs += " -d \"" + strProj + "/build/classes\""; // output |
| 96 | + strArgs += " \"" + strProj |
| 97 | + + "/src/org/me/androiddemo/MainActivity.java\""; |
| 98 | + |
| 99 | + BatchCompiler.compile(strArgs, new PrintWriter(System.out), |
| 100 | + new PrintWriter(System.err), null); |
| 101 | + |
| 102 | + } catch (IOException e) { |
| 103 | + // TODO Auto-generated catch block |
| 104 | + e.printStackTrace(); |
| 105 | + } |
| 106 | + return null; |
| 107 | + } |
| 108 | + |
| 109 | + } |
| 110 | +} |
0 commit comments