Skip to content

Commit d91586a

Browse files
committed
Added Dex generation feature
1 parent ca7b114 commit d91586a

32 files changed

+268
-125
lines changed

.DS_Store

6 KB
Binary file not shown.

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/AndroidProjectSystem.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/appInsightsSettings.xml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetSelector.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/migrations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,22 @@ Open and compile the project with [AndroidIDE](https://github.com/AndroidIDEOffi
2020
### Install with shell commands
2121

2222
It can be imported into DroidScript with this example:
23-
23+
Start the terminal in the project folder: `~/AndroidStudioProjects/JavaCompiler`
2424
```sh
2525
cd app/build/outputs/apk/debug
2626
rm -r temp
27+
mkdir temp
2728
unzip app-debug.apk -d temp
2829
cd temp
2930
zip JavaCompiler.jar classes*.dex
30-
rm classes.dex
3131
cp -r assets/* .
32-
cp -r lib/* .
33-
rm -r lib
34-
rm -r assets
35-
rm -r res
36-
rm AndroidManifest.xml
37-
rm resources.arsc
38-
rm -r META-INF
39-
zip -r ../JavaCompiler.ppk *.
40-
41-
cd ..
42-
export PATH=$PATH:~/Library/Android/sdk/platform-tools/
32+
zip JavaCompiler.ppk JavaCompiler* android.jar
4333
adb push JavaCompiler.ppk /sdcard/Android/data/com.smartphoneremote.androidscriptfree/files/DroidScript/Plugins/JavaCompiler.ppk
34+
echo COMPLETED
4435
```
4536

37+
Now (re)open DroidScript and wait for the "plugin loaded" message.
38+
4639
### Install manually
4740

4841
* Unzip the APK.

app/.DS_Store

6 KB
Binary file not shown.

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ android {
3030

3131
compileOptions {
3232
coreLibraryDesugaringEnabled true
33-
33+
3434
sourceCompatibility JavaVersion.VERSION_1_8
3535
targetCompatibility JavaVersion.VERSION_1_8
3636
}
3737
}
3838

3939
dependencies {
4040
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.4'
41-
42-
implementation fileTree(dir: 'libs', include: ['*.jar'])
41+
42+
implementation files('libs/dx-1.16.jar')
43+
implementation files('libs/nb-javac-17.0.0.4-android.jar')
4344
}

app/libs/dx-1.16.jar

1 MB
Binary file not shown.

app/proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# For more details, see
66
# http://developer.android.com/guide/developing/tools/proguard.html
7+
# Prevent R8 from leaving Data object members always null
78

89
# If your project uses WebView with JS, uncomment the following
910
# and specify the fully qualified class name to the JavaScript interface

app/src/.DS_Store

6 KB
Binary file not shown.

app/src/main/.DS_Store

6 KB
Binary file not shown.

app/src/main/assets/JavaCompiler.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ <h3>Methods</h3>
166166
<a href="#pop_dsc_008" data-transition="pop" data-rel="popup">SetOutputFolder</a>(
167167
<a href="#pop_str_ptd" data-transition="pop" data-rel="popup">path</a> )
168168
</div>
169+
<div class="samp">
170+
<a href="#pop_dsc_009" data-transition="pop" data-rel="popup">GenerateDexFile</a>(
171+
<a href="#pop_str_ptd" data-transition="pop" data-rel="popup">jarPath</a>) → <b>String</b>
172+
</div>
169173

170174
</div>
171175

@@ -181,6 +185,7 @@ <h3>Methods</h3>
181185
<div data-role="popup" id="pop_dsc_006" class="ui-content"><b>jac.GetDiagnosticMessages</b><br>Log records generated during compilation.</div>
182186
<div data-role="popup" id="pop_dsc_007" class="ui-content"><b>jac.SetOptions</b><br>Compilation flags.</div>
183187
<div data-role="popup" id="pop_dsc_008" class="ui-content"><b>jac.SetOutputFolder</b><br>Output folder for adding packages created during compilation.</div>
188+
<div data-role="popup" id="pop_dsc_009" class="ui-content"><b>jac.GenerateDexFile</b><br>It converts the given jar file to dex file and adds classes.dex file to the output folder.</div>
184189
</div>
185190
</body>
186191

app/src/main/assets/JavaCompiler.inc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
2-
//Add CreateJavaCompiler method to global app object.
3-
app.CreateJavaCompiler = function( options ) {
4-
return new CreateJavaCompiler( options );
5-
}
6-
7-
//Plugin wrapper object.
8-
function CreateJavaCompiler( options )
9-
{
1+
2+
//Add CreateJavaCompiler method to global app object.
3+
app.CreateJavaCompiler = options => new CreateJavaCompiler( options );
4+
5+
//Plugin wrapper object.
6+
function CreateJavaCompiler( options )
7+
{
108
const plg = _CreatePlugin( "com.candlelight.javacompiler.plugins.user.JavaCompiler", options );
119

1210
const id = plg.CreateObj("JavaCompiler", options);
13-
let inst;
11+
let inst;
1412

1513
if( id ) inst = new SObj(id, "jac");
1614
else throw Error("CreateJavaCompiler: Something going wrong.");
@@ -23,9 +21,10 @@ function CreateJavaCompiler( options )
2321
inst.AddPlatformJarFile = path => send("addPlatformJarFile", app.RealPath(path));
2422
inst.AddJarFile = path => send("addJarFile", app.RealPath(path));
2523
inst.SetOutputFolder = path => send("setOutputFolder", app.RealPath(path));
26-
inst.Compile = () => send("compile");// === "true";
24+
inst.Compile = () => send("compile") === "true";
2725
inst.GenerateJarFile = () => send("generateJarFile");
26+
inst.GenerateDexFile = (jarPath) => send("generateDexFile", app.RealPath(jarPath));
2827
inst.GetDiagnosticMessages = () => send("getDiagnosticMessages");
2928

30-
return inst;
29+
return inst;
3130
}

app/src/main/java/.DS_Store

6 KB
Binary file not shown.

app/src/main/java/com/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

app/src/main/java/com/candlelight/javacompiler/plugins/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
package com.candlelight.javawrapper.plugins;
2+
package com.candlelight.javacompiler.plugins;
33

44
import android.app.Activity;
55

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.candlelight.javacompiler.plugins.user;
2+
3+
import android.util.Log;
4+
5+
import com.xiaoyv.dx.command.Main;
6+
7+
import java.nio.file.Paths;
8+
9+
public class JarToDex {
10+
public String outputPath;
11+
12+
String startConversion(String jarPath) {
13+
String outFile = Paths.get(this.outputPath)
14+
.resolve("classes.dex")
15+
.toString();
16+
Log.e("JavaCompiler", "OKU:" + outFile);
17+
String[] args = {
18+
"--dex",
19+
"--no-strict",
20+
"--min-sdk-version=26",
21+
"--output=" + outFile,
22+
jarPath
23+
};
24+
Log.e("JavaCompiler", "OKU:" + String.join(",", args));
25+
26+
try {
27+
Main.main(args);
28+
} catch (Exception e) {
29+
return "Error: " + e.getClass().getSimpleName() + " - " + e.getMessage();
30+
}
31+
32+
return "";
33+
}
34+
}

0 commit comments

Comments
 (0)