Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 6 commits into from
Closed

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

wants to merge 6 commits into from

Conversation

omeraydindev
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Oct 5, 2021

Why you don't start moding sketchware pro agin?

@khaled-0
Copy link
Contributor

khaled-0 commented Oct 5, 2021

Kotlin might be nub but this is ultra por indeed

@omeraydindev
Copy link
Contributor Author

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

@jian6137
Copy link

jian6137 commented Oct 6, 2021

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

@JavkhlanK JavkhlanK added feature A new feature good first contribution When a contributor finally commits great changes or additions needs attention When there are major changes and needs more attention from multiple contributors to review them labels Oct 8, 2021
@tyron12233
Copy link
Contributor

Kotlin Blocks?

@PranavPurwar

This comment was marked as spam.

@omeraydindev
Copy link
Contributor Author

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
Copy link

dang kotlin

@arab-ware
Copy link

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
Copy link

@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
Copy link
Contributor Author

@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
Copy link

@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
Copy link
Contributor Author

@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
Copy link

arab-ware commented Feb 22, 2022

@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
Copy link

@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
Copy link
Contributor Author

@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
Copy link

arab-ware commented Feb 28, 2022

@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
Copy link
Contributor Author

@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
Copy link

@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
Copy link
Contributor

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

@Arashvscode

This comment was marked as spam.

@Arashvscode

This comment was marked as spam.

JavkhlanK added a commit that referenced this pull request Jun 8, 2022
…as comment

Also removes an unused Gson field. Not changing field names just yet so that there's less to fix when merging PR #247.
@JavkhlanK
Copy link
Member

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 JavkhlanK added the help wanted Extra attention is needed label Jun 12, 2022
@hasrat-ali hasrat-ali assigned hasrat-ali and unassigned hasrat-ali Jun 15, 2022
@JavkhlanK JavkhlanK self-assigned this Jun 16, 2022
@JavkhlanK
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

These patches were merged in, see 601646a...4b7b979.

@JavkhlanK JavkhlanK added the merged This pull request was merged, it's only GitHub not showing it as merged. label Jun 21, 2022
@JavkhlanK JavkhlanK closed this Jun 21, 2022
@ilyassesalama
Copy link
Member

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature good first contribution When a contributor finally commits great changes or additions help wanted Extra attention is needed merged This pull request was merged, it's only GitHub not showing it as merged. needs attention When there are major changes and needs more attention from multiple contributors to review them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet