Sketchware-Pro / Sketchware-Pro

Sketchware Pro's sources in Java. Now anyone can contribute to Sketchware Pro.
https://sketchware.pro
Other
863 stars 254 forks source link

feat: Add Kotlin support (Android 8+) #247

Closed omeraydindev closed 1 year ago

omeraydindev commented 2 years ago

This PR adds full Kotlin support (for Android 8+). Kotlin files can be called from Java and vice versa. kotlin-stdlib is added automatically if any Kotlin files are present in the project. .kt files can be added in Java(/Kotlin) Manager, or in the following dirs:

/.sketchware/mysc/xxx/app/src/main/java /.sketchware/data/xxx/files/java

All credits go to tyron for porting kotlinc to Android and making this possible πŸ‘

Please take your time to review & test this thoroughly before merging it, as there might be stuff that I've missed (although I did test it and it seems to be working well.)

By the way I've already built an APK with this PR on top of the latest v6.4.0 beta 6 release, here you go if you want to build the newer versions on top of it: here


If not, here are the exact steps to produce the APK above: (I use MT Manager but ApkTool can be used as well)

1- Download https://github.com/MikeAndrson/kotlinc-android and open it in Android Studio, then Generate a Signed APK. (alternatively you can download https://github.com/tyron12233/CodeAssist/ and copy its build-logic & kotlinc modules to a new project then generate an APK)

2- Download the latest release from https://github.com/Sketchware-Pro/Sketchware-Pro/releases. (beta 6 as of writing this)

3- Delete the kotlin package in classes8.dex in Sketchware Pro's APK from step 2.

4- Copy all JAR resources from the APK in step 1 to Sketchware Pro's APK from step 2. (including META-INF/ & kotlinManifest.properties !)

5- Copy the extracted DEX files from the APK in step 1 to Sketchware Pro's APK from step 2. (Remember to rename them first, as to not overwrite any DEX in the target APK)

-> Below steps are usual stuff but adding them for completeness.

6- Build Sketchware Pro from source and copy (& overwrite) the classes below to the Sketchware Pro APK in step 2.

DesignActivity, Dp, ExportProjectActivity, ManageJavaActivity, SrcCodeEditor, yq, KotlinCompilerUtil, KotlinDescription, DiagnosticKt, DiagnosticCollectorKt, KotlinCompilerKt.

7- Replace "Java" to "Java/Kotlin" & "Import Java files" to "Import Java/Kotlin files" in resources.arsc.

8- Sign the final APK if you haven't already.

ghost commented 2 years ago

Why you don't start moding sketchware pro agin?

khaled-0 commented 2 years ago

Kotlin might be nub but this is ultra por indeed

omeraydindev commented 2 years ago

Didn't test the plugins support but it should work as well

jian6137 commented 2 years ago

Good One. Can't wait for it to be implemented

tyron12233 commented 2 years ago

Kotlin Blocks?

PranavPurwar commented 2 years ago

Bro it's very good, the compilation works but when i create an activity with setContentView(R.layout.main), i get error saying unresolved R while compiling kotlin (or something related to it even with it's import) which i think is because the R.java file is not compiled and put in classpath before kotlin compiler is run

omeraydindev commented 2 years ago

Bro it's very good, the compilation works but when i create an activity with setContentView(R.layout.main), i get error saying unresolved R while compiling kotlin (or something related to it even with it's import) which i think is because the R.java file is not compiled and put in classpath before kotlin compiler is run

Oops. Should be fixed now.

ItsKruistz commented 2 years ago

dang kotlin

arab-ware commented 2 years ago

This PR adds full Kotlin support (for Android 8+). Kotlin files can be called from Java and vice versa. kotlin-stdlib is added automatically if any Kotlin files are present in the project. .kt files can be added in Java(/Kotlin) Manager, or in the following dirs:

/.sketchware/mysc/xxx/app/src/main/java /.sketchware/data/xxx/files/java

All credits go to tyron for porting kotlinc to Android and making this possible πŸ‘

Please take your time to review & test this thoroughly before merging it, as there might be stuff that I've missed (although I did test it and it seems to be working well.)

By the way I've already built an APK with this PR on top of the latest v6.4.0 beta 6 release, here you go if you want to build the newer versions on top of it: here

If not, here are the exact steps to produce the APK above: (I use MT Manager but ApkTool can be used as well)

1- Download https://github.com/MikeAndrson/kotlinc-android and open it in Android Studio, then Generate a Signed APK. (alternatively you can download https://github.com/tyron12233/CodeAssist/ and copy its build-logic & kotlinc modules to a new project then generate an APK)

  • Extract DEX files from the APK, delete ma.kotlinc_standalone package from the DEX files.

2- Download the latest release from https://github.com/Sketchware-Pro/Sketchware-Pro/releases. (beta 6 as of writing this)

3- Delete the kotlin package in classes8.dex in Sketchware Pro's APK from step 2.

4- Copy all JAR resources from the APK in step 1 to Sketchware Pro's APK from step 2. (including META-INF/ & kotlinManifest.properties !)

5- Copy the extracted DEX files from the APK in step 1 to Sketchware Pro's APK from step 2. (Remember to rename them first, as to not overwrite any DEX in the target APK)

-> Below steps are usual stuff but adding them for completeness.

6- Build Sketchware Pro from source and copy (& overwrite) the classes below to the Sketchware Pro APK in step 2.

DesignActivity, Dp, ExportProjectActivity, ManageJavaActivity, SrcCodeEditor, yq, KotlinCompilerUtil, KotlinDescription, DiagnosticKt, DiagnosticCollectorKt, KotlinCompilerKt.

7- Replace "Java" to "Java/Kotlin" & "Import Java files" to "Import Java/Kotlin files" in resources.arsc.

8- Sign the final APK if you haven't already.

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

omeraydindev commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

omeraydindev commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

Why no reply bro :) at least say no , πŸ€πŸ’š

omeraydindev commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

Why no reply bro :) at least say no , πŸ€πŸ’š

Sorry, haven't been able to look into it due to work/school. Do you want the Kotlin patch on v6.4.0 Beta 6 or v6.4.0 test build 01 ?

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

Why no reply bro :) at least say no , πŸ€πŸ’š

Sorry, haven't been able to look into it due to work/school. Do you want the Kotlin patch on v6.4.0 Beta 6 or v6.4.0 test build 01 ?

Anything you can.... but it is better if you mod rc mod..., take you time .

omeraydindev commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

Why no reply bro :) at least say no , πŸ€πŸ’š

Sorry, haven't been able to look into it due to work/school. Do you want the Kotlin patch on v6.4.0 Beta 6 or v6.4.0 test build 01 ?

Anything you can.... but it is better if you mod rc mod..., take you time .

Hi @arab-ware, sorry it took so long but I applied the Kotlin patch on v6.4.0 test build 01. Here you go: https://drive.google.com/file/d/1JRPiUaM8kfX0XQPk_wRUSorBbQR206uT/view?usp=sharing

image

arab-ware commented 2 years ago

@MikeAndrson ... thank you for this but kotlin is compiling is being executed before java is compiling so kotlin classes cannot call R class because it is java auto generated class.... I hope you fix this soon bro

I had fixed that bug in this commit after @PranavPurwar pointed it out, it should work now.

Ok ... I will try to use my litte knowledge in modding to fix that , could you edit the given apk file you shared??? When you are free , in case I can't do it myself , thanks in advance

πŸ‘ I'll try to update the APK this week

Hello bro. Did you finish it?

Why no reply bro :) at least say no , πŸ€πŸ’š

Sorry, haven't been able to look into it due to work/school. Do you want the Kotlin patch on v6.4.0 Beta 6 or v6.4.0 test build 01 ?

Anything you can.... but it is better if you mod rc mod..., take you time .

Hi @arab-ware, sorry it took so long but I applied the Kotlin patch on v6.4.0 test build 01. Here you go: https://drive.google.com/file/d/1JRPiUaM8kfX0XQPk_wRUSorBbQR206uT/view?usp=sharing

image thank you as the number of your blood cells

khaled-0 commented 2 years ago

How about rebasing this branch so it would support Github Actions.

Arashvscode commented 2 years ago

I do not know if I will support kotlin in the official versions

Arashvscode commented 2 years ago

Jbk plz add kotlin

JavkhlanK commented 1 year ago

Can't get this to compile in debug mode. Creating a release APK works.

image

I really wonder why that happens, and also, why when compiling Kotlin code?

JavkhlanK commented 1 year ago

Update: Managed to merge it while also successfully building an APK. Gotta figure out how to remove the kotlin-stdlib dependency automatically added by the Kotlin Gradle plugin, and also instead use the JARs with the working classes, not the classpath ones.

hasrat-ali commented 1 year ago

Update: Managed to merge it while also successfully building an APK. Gotta figure out how to remove the kotlin-stdlib dependency automatically added by the Kotlin Gradle plugin, and also instead use the JARs with the working classes, not the classpath ones.

I think it should be merged. We will figure out other things later.

JavkhlanK commented 1 year ago

Update: Managed to merge it while also successfully building an APK. Gotta figure out how to remove the kotlin-stdlib dependency automatically added by the Kotlin Gradle plugin, and also instead use the JARs with the working classes, not the classpath ones.

I think it should be merged. We will figure out other things later.

I'm already working on it.

JavkhlanK commented 1 year ago

Turns out that simply copying the Gradle modules to Sketchware Pro is much easier than messing around with converted .class files in JARs, excluding Gradle dependencies, etc. Now working on cleanly separating Kotlin compile support from the minApi 21 flavor.

JavkhlanK commented 1 year ago

These patches were merged in, see 601646a309723ea166fa97c24a89aab50535a22f...4b7b979b1b38adee4e14ec2feea1b8b8b4310ce2.

ilyassesalama commented 1 year ago

πŸŽ‰