Skip to content

Commit b10a06c

Browse files
committed
dev: jdk 1.8 javac
1 parent b325b76 commit b10a06c

700 files changed

Lines changed: 196073 additions & 37 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/gradle.xml

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

app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ plugins {
44
}
55

66
android {
7-
compileSdk 32
7+
compileSdk rootProject.targetSdk
88

99
buildFeatures {
1010
viewBinding true
1111
}
1212

1313
defaultConfig {
1414
applicationId "com.xiaoyv.javaengine"
15-
minSdkVersion 21
16-
targetSdkVersion 32
15+
minSdkVersion rootProject.minSdkVersion
16+
targetSdkVersion rootProject.targetSdk
1717
versionCode 1
1818
versionName "1.0"
1919

@@ -43,7 +43,8 @@ dependencies {
4343
implementation 'com.blankj:utilcodex:1.31.0'
4444

4545
implementation 'io.github.xiaoyvyv:compiler-d8:1.0.2'
46-
// implementation project(':compiler-d8')
46+
// implementation project(':compiler-d8')
47+
implementation project(':compiler-format')
4748

4849
testImplementation 'junit:junit:4.13.2'
4950
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

app/src/main/java/com/xiaoyv/javaengine/CompileActivity.kt

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import androidx.appcompat.app.AlertDialog
88
import androidx.appcompat.app.AppCompatActivity
99
import com.blankj.utilcode.util.FileIOUtils
1010
import com.blankj.utilcode.util.PathUtils
11+
import com.google.googlejavaformat.java.Formatter
12+
import com.google.googlejavaformat.java.JavaFormatterOptions
1113
import com.xiaoyv.java.compiler.JavaEngine
1214
import com.xiaoyv.javaengine.databinding.ActivitySingleSampleBinding
1315
import kotlinx.coroutines.*
1416
import java.io.File
1517
import kotlin.coroutines.resume
1618
import kotlin.coroutines.resumeWithException
1719

20+
1821
/**
1922
* CompileActivity
2023
*
@@ -50,13 +53,23 @@ class CompileActivity : AppCompatActivity(), CoroutineScope by MainScope() {
5053

5154
binding.toolbar.menu.add("Run")
5255
.setOnMenuItemClickListener {
53-
runProgram()
56+
formatCode()
57+
// runProgram()
5458
true
5559
}.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
5660

5761

5862
}
5963

64+
private fun formatCode() {
65+
val codeText = binding.codeText.text.toString()
66+
val formatSource = Formatter(JavaFormatterOptions.builder()
67+
.style(JavaFormatterOptions.Style.GOOGLE)
68+
.build())
69+
.formatSource(codeText)
70+
binding.codeText.setText(formatSource)
71+
}
72+
6073
/**
6174
* [JavaEngine.CompileExceptionHandler] 为内部编译相关的协程作用域 默认异常捕获实现。
6275
*
@@ -104,30 +117,30 @@ class CompileActivity : AppCompatActivity(), CoroutineScope by MainScope() {
104117

105118
binding.printView.append("Run dex start...\n\n")
106119

107-
// JavaEngine.
108-
val programConsole = JavaEngine.javaProgram.run(dexFile, arrayOf("args"),
109-
chooseMainClassToRun = { classes, continuation ->
110-
val dialog = AlertDialog.Builder(this@CompileActivity)
111-
.setTitle("请选择一个主函数运行")
112-
.setItems(classes.toTypedArray()) { p0, p1 ->
113-
p0.dismiss()
114-
continuation.resume(classes[p1])
115-
}
116-
.setCancelable(false)
117-
.setNegativeButton("取消") { d, v ->
118-
d.dismiss()
119-
continuation.resumeWithException(Exception("取消操作"))
120-
}.create()
121-
122-
dialog.show()
123-
dialog.setCanceledOnTouchOutside(false)
124-
},
125-
printOut = {
126-
binding.printView.append(it)
127-
},
128-
printErr = {
129-
binding.printView.append(Html.fromHtml("<font color=\"#FF0000\">$it</font>"))
130-
})
120+
// JavaEngine.
121+
val programConsole = JavaEngine.javaProgram.run(dexFile, arrayOf("args"),
122+
chooseMainClassToRun = { classes, continuation ->
123+
val dialog = AlertDialog.Builder(this@CompileActivity)
124+
.setTitle("请选择一个主函数运行")
125+
.setItems(classes.toTypedArray()) { p0, p1 ->
126+
p0.dismiss()
127+
continuation.resume(classes[p1])
128+
}
129+
.setCancelable(false)
130+
.setNegativeButton("取消") { d, v ->
131+
d.dismiss()
132+
continuation.resumeWithException(Exception("取消操作"))
133+
}.create()
134+
135+
dialog.show()
136+
dialog.setCanceledOnTouchOutside(false)
137+
},
138+
printOut = {
139+
binding.printView.append(it)
140+
},
141+
printErr = {
142+
binding.printView.append(Html.fromHtml("<font color=\"#FF0000\">$it</font>"))
143+
})
131144

132145
binding.btSend.setOnClickListener {
133146
val input = binding.inputEdit.text.toString()

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ plugins {
55
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
66
}
77

8+
ext {
9+
minSdkVersion = 24
10+
targetSdk = 32
11+
}
12+
813
task clean(type: Delete) {
914
delete rootProject.buildDir
1015
}

compiler-d8/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ plugins {
66
apply from: '../maven.gradle'
77

88
android {
9-
compileSdk 32
9+
compileSdk rootProject.targetSdk
1010

1111
defaultConfig {
12-
minSdk 21
13-
targetSdk 32
12+
minSdk rootProject.minSdkVersion
13+
targetSdk rootProject.targetSdk
1414

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16-
consumerProguardFiles "consumer-rules.pro"
1716
}
1817

1918
buildTypes {

compiler-d8/consumer-rules.pro

Whitespace-only changes.

compiler-format.zip

18.2 MB
Binary file not shown.

compiler-format/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

compiler-format/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
apply from: '../maven.gradle'
7+
8+
android {
9+
compileSdk rootProject.targetSdk
10+
11+
defaultConfig {
12+
minSdk rootProject.minSdkVersion
13+
targetSdk rootProject.targetSdk
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
kotlinOptions {
29+
jvmTarget = '1.8'
30+
}
31+
}
32+
33+
dependencies {
34+
implementation 'com.google.guava:guava:31.1-android'
35+
implementation project(":compiler-jdk8")
36+
37+
testImplementation 'junit:junit:4.13.2'
38+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
39+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
40+
}

compiler-format/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)