Skip to content

Commit

Permalink
add jar to dex
Browse files Browse the repository at this point in the history
  • Loading branch information
appt2 committed Mar 15, 2024
1 parent 1312068 commit 536b37c
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 131 deletions.
50 changes: 50 additions & 0 deletions .androidide/editor/openedFiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"allFiles": [
{
"file": "/storage/emulated/0/AndroidIDEProjects/Ghost-web-ide/android-tools/src/main/java/ninjacoder/ghostide/androidtools/r8/android/R8Tools.java",
"selection": {
"end": {
"column": 51,
"index": 1244,
"line": 25
},
"start": {
"column": 51,
"index": 1244,
"line": 25
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/Ghost-web-ide/android-tools/build.gradle",
"selection": {
"end": {
"column": 2,
"index": 468,
"line": 23
},
"start": {
"column": 2,
"index": 468,
"line": 23
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/Ghost-web-ide/app/src/main/java/Ninja/coder/Ghostemane/code/FiledirActivity.java",
"selection": {
"end": {
"column": 19,
"index": 2855,
"line": 77
},
"start": {
"column": 19,
"index": 2855,
"line": 77
}
}
}
],
"selectedFile": "/storage/emulated/0/AndroidIDEProjects/Ghost-web-ide/app/src/main/java/Ninja/coder/Ghostemane/code/FiledirActivity.java"
}
2 changes: 1 addition & 1 deletion android-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
}
dependencies {
//add your dependencies
implementation 'com.android.tools:r8:8.3.37'
implementation 'com.android.tools:r8:8.3.37'
implementation "androidx.appcompat:appcompat:1.7.0-alpha03"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "com.google.android.material:material:1.12.0-alpha03"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,43 @@

import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Looper;
import com.android.tools.r8.CompilationMode;
import com.android.tools.r8.OutputMode;
import com.android.tools.r8.R8;
import com.android.tools.r8.R8Command;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.android.tools.r8.D8;
import com.google.android.material.shape.CornerFamily;
import com.google.android.material.shape.MaterialShapeDrawable;
import com.google.android.material.shape.ShapeAppearanceModel;
import java.util.ArrayList;

public class R8Tools {
public void CompileR8Dex(String input, String output, int minapi) throws Exception {
var path = Paths.get(input);
var outputFile = Paths.get(output);
if (path.endsWith(".dex")) {
R8Command command =
R8Command.builder()
.setMinApiLevel(minapi)
.setAndroidPlatformBuild(true)
.addProgramFiles(path)
.setOutput(outputFile, OutputMode.DexIndexed)
.setMode(CompilationMode.RELEASE)
.build();
R8.run(command);
}
}

public void onlyCompile(String input, String output, int api, Context context) {
public void onlyCompile(String input, String output, int api, Context context,OnItemChange item) {
var dialog = new ProgressDialog(context, ProgressDialog.THEME_DEVICE_DEFAULT_DARK);
dialog.setMessage("Compile jar to dex");
dialog.setTitle(" jar to dex");
dialog.setMessage("It may take a few minutes depending on your DEX");
dialog.setCancelable(false);
MaterialShapeDrawable shap = new MaterialShapeDrawable(ShapeAppearanceModel.builder().setAllCorners(CornerFamily.ROUNDED,20f).build());
shap.setFillColor(ColorStateList.valueOf(Color.parseColor("#FF0D1423")));
shap.setStroke(0.5f,ColorStateList.valueOf(Color.parseColor("#FF2EDCFF")));
dialog.getWindow().setBackgroundDrawable(shap);
dialog.show();

ArrayList<String> args = new ArrayList<>();
new Thread(
() -> {
try {
CompileR8Dex(input, output, api);
args.clear();
args.add("--release");
args.add("--lib");
args.add("/storage/emulated/0/GhostWebIDE/android/android.jar");
args.add("--output");
args.add(output);
args.add(input);
D8.main(args.toArray(new String[0]));

} catch (Exception err) {
runOnUiThread(
() -> {
Expand All @@ -47,14 +50,18 @@ public void onlyCompile(String input, String output, int api, Context context) {
if (dialog != null) {
dialog.setMessage("Done");
dialog.dismiss();
item.onItemResult();
}
});
})
.start();
}
}

private void runOnUiThread(Runnable d) {
var handler = new Handler(Looper.getMainLooper());
handler.post(d);
}
public interface OnItemChange{
public void onItemResult();
}
}
Binary file added app/src/main/assets/android.7z
Binary file not shown.
Binary file removed app/src/main/assets/android.zip
Binary file not shown.
Loading

0 comments on commit 536b37c

Please sign in to comment.