-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add first steps: Welcome screen and build.gradle
code injection screens
#1
base: main
Are you sure you want to change the base?
Conversation
Set up the tool window that will be displayed and the first screen that users will see, the welcome screen.
- This is the first SDK setup step (after the welcome screen) - Adds next button to welcome screen to get to this step - Injects `gradlePluginPortal()` and `classpath "gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.9, 0.99.99]"`
- This is the second SDK setup step (after the welcome screen and project build.gradle) - Injects `implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'` and `apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'` - If project directory is not just BASE_PROJECT_PATH/app/build.gradle, the user has to specify the path, for example `~/Documents/outerProject/subProject/app`
build.gradle
code injectionbuild.gradle
code injection screens
dfc729c
to
22c9ccc
Compare
* Check for a different substring (named appendId) to avoid adding duplicate code if it already exists. This will avoid overlooking dependencies with version variables. * For example, check for the existance of "com.onesignal:OneSignal" instead of "implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'" when deciding to inject the latter.
* Add home navigation by cancel button
Placeholder for the plugin icon
These were not in my files and everything ran ok, but adding them in case they are actually needed
- add showNotification to utils - it helps to debug while working, to see what values are - use showNotification in code, and need to pass project to use it - this will be removed later, for debugging purposes only for now
22c9ccc
to
246e679
Compare
|
||
dependencies { | ||
|
||
classpath 'com.onesignal:onesignal-gradle-plugin:[0.8.1, 0.99.99]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to latest version, which is 0.14.0
. Also we should probably have a shared definition for this version string, since it is used in multiple spots.
val appendIdMatch = appendIdRegex.find(this)?.range | ||
|
||
showNotification(project, "appendId string: $appendId match: $appendIdMatch") | ||
return if (appendIdMatch == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be easier to read as early returns, instead of a large nested if-else block. Smaller if-else blocks can make code easier to read than some other ways, but this one is pretty long.
// injecting com.onesignal:OneSignal dependency | ||
|
||
content = content.appendStringByMatch( | ||
"implementation \"androidx.appcompat:appcompat:[^']*\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These string searches look to be checking some possible dependences that the project might have. This doesn't look like it can account for any unexpected dependency so it looks like this approach won't work with may projects.
Did some searching and it looks like there is an Intellij API to read the build.gradle
file and modify it (com.android.tools.idea.gradle.dsl.model.GradleBuildModel
):
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000106044-How-to-add-dependencies-to-gradle-file-from-IntelliJ-DEA-plugin-
} | ||
|
||
//runIde { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this? Or add a comment of a reason why you would want to uncomment this, such as to test something specific.
Background Information
This project was created in IntelliJ IDEA 2020.3.3 (Build #IC-203.7717.56) with Java 11.
There may be compatibility challenges. I would like to know if you are able to open this project, build it, or add it to another Android project, and what errors you encounter.
I am also not sure if the
build.gradle
contents are best.Design and Copy
For now, there was not a focus on the text, wording, or design. Some of the text is inaccurate too. It is mainly focused on the logic so any words or styles are temporary and should be changed.
Panels
In this PR, there are 3 panels (screens) created.
1: Welcome Screen
2: Project-Level
build.gradle
Code Injection ScreenSDKSetupFirstStepPanel
andSDKSetupFirstStepController
.gradlePluginPortal()
if not there tobuildscript > repositories
"classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.9, 0.99.99]'"
if not there tobuildscript > dependencies
3: App-Level
build.gradle
Code Injection ScreenSDKSetupSecondStepPanel
andSDKSetupSecondStepController
."implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'"
.com.onesignal.androidsdk.onesignal-gradle-plugin
BASE_PROJECT_PATH/app/build.gradle
to find the file. If the project structure is different, such as is the example project in the OneSignal-Android-SDK, the user will have to input their full path into the text box.Functions
String.appendStringByMatch()
is the primary helper function to inject code into the user's files.build.gradle
."com.onesignal:OneSignal"
before adding that dependency."mavenCentral()"
at the end of which we inject"gradlePluginPortal()"
.Limitations and Improvements
gradlePluginPortal()
looks forjcenter()
ormavenCentral()
to anchor to, but if the user hasmavenCentral()
inallprojects
first andbuildscript
later in the file, the plugin will inject the code underallprojects
.""
or single quotes''
, which can be made cleanerTesting
I manually tested using the OneSignal-Android-SDK example app, another Java project, and a new Kotlin Android Studio project.
How to Run
./gradlew clean build
. When I build on IDEA 2020.3.3, I do get an error inbuildSearchableOptions
that is this issue (it should still build successfully even with the error output).gradle
files during testing, you may need to sync thegradle
files for the plugin to have the latest changes.