titanium-sdk
titanium-sdk copied to clipboard
feat(android): be able to add plugins to build.gradle
feat(android): added classpathes to manifest feat(android): add plugins to manifest feat(android): custom root.build.gradle for modules
- classpathes will be added to the root project build.gradle to allow plugins to be identified.
- plugins will be added to the module build.gradle file.
Just a minor code style issue, thanks!
Of course! Thanks 🙏
CR looks good from my end. @m1ga Any objections?
I guess I need to add a couple of more things to make this PR feature solid.
i've not tested it as I don't have any test case or knowledge how to use plugins in a gradle file. But if it works for you and doens't break the usual stuff (module build, app build, hyperloop app, kitchensink app) then go for it 😄 if it is something "non standard" gradle stuff there should be some documentation how to use it
@hansemannn @m1ga This was the last commit needed to this PR, I've tested it from my side and it's all good now and ready to be merged, as for the documentation of how to use this, we need to add the update here, if you can tag me on where this is editable so I can work on the documentation of this new feature.
Nice, that will be in this repo: https://github.com/tidev/titanium-docs/tree/main/docs/guide/Titanium_SDK/Titanium_SDK_How-tos/Extending_Titanium_Mobile
Cool
Hyperloop apps won't build.
[ERROR] [GRADLE]
[ERROR] [GRADLE] FAILURE: Build failed with an exception.
[ERROR] [GRADLE]
[ERROR] [GRADLE] * Where:
[ERROR] [GRADLE] Build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle' line: 2
[ERROR] [GRADLE]
[ERROR] [GRADLE] * What went wrong:
[ERROR] [GRADLE] Could not compile build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle'.
[ERROR] [GRADLE] > startup failed:
[ERROR] [GRADLE] build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle': 2: Unexpected input: '{' @ line 2, column 13.
The generated build.gradle file looks like this:
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
<% for (let i = 0; i < classpathes.length; i++) {%>
classpath '<%= classpathes[i] %>'
<% } %>
}
so it didn't replace the loop.
Module also won't build:
[ERROR] TypeError: Cannot read properties of undefined (reading 'split')
at AndroidModuleBuilder.generateRootProjectFiles (/home/miga/.titanium/mobilesdk/linux/12.3.0/android/cli/commands/_buildModule.js:518:42)
at async AndroidModuleBuilder.run (/home/miga/.titanium/mobilesdk/linux/12.3.0/android/cli/commands/_buildModule.js:315:3)
[ERROR] An error occurred during build after 24ms
[ERROR] Cannot read properties of undefined (reading 'split')
@m1ga can you please review this, thanks!
with the fixes I still get
[ERROR] [GRADLE] FAILURE: Build failed with an exception.
[ERROR] [GRADLE]
[ERROR] [GRADLE] * Where:
[ERROR] [GRADLE] Build file '/home/miga/dev/ti.mlkit/android/build/build.gradle' line: 14
when building a module as it will add an empty classpath
line to the build/build.gradle:
buildscript {
ext.kotlin_version = '1.8.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath ''
}
}
...
The hyperloop error also still exists. To test it: clone and build https://github.com/tidev/hyperloop-examples
@m1ga I'll try to work on it today and finish it ASAP.
@AbdullahFaqeir Any updates here? We'd love to include it in our next release!
@AbdullahFaqeir Any updates here? We'd love to include it in our next release! @m1ga I'll get back and work on this within two days
building modules still fails with
[ERROR] TypeError: Cannot read properties of undefined (reading 'split')
at AndroidModuleBuilder.generateRootProjectFiles (/home/miga/.titanium/mobilesdk/linux/12.6.0/android/cli/commands/_buildModule.js:519:40)
at async AndroidModuleBuilder.run (/home/miga/.titanium/mobilesdk/linux/12.6.0/android/cli/commands/_buildModule.js:316:3)
[ERROR] An error occurred during build after 11ms
[ERROR] Cannot read properties of undefined (reading 'split')
and hyperloop example
[ERROR] [GRADLE]
[ERROR] [GRADLE] FAILURE: Build failed with an exception.
[ERROR] [GRADLE]
[ERROR] [GRADLE] * Where:
[ERROR] [GRADLE] Build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle' line: 1
[ERROR] [GRADLE]
[ERROR] [GRADLE] * What went wrong:
[ERROR] [GRADLE] Could not compile build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle'.
[ERROR] [GRADLE] > startup failed:
[ERROR] [GRADLE] build file '/home/miga/tools/hyperloop-examples/build/hyperloop/android/build.gradle': 1: Unexpected input: '{' @ line 1, column 13.
[ERROR] [GRADLE] buildscript {
[ERROR] [GRADLE] ^
[ERROR] [GRADLE]
[ERROR] [GRADLE] 1 erro
because the gradle looks like this:
...
classpath 'com.google.gms:google-services:4.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
<% for (let i = 0; i < classpaths.length; i++) {%>
classpath '<%= classpaths[i] %>'
<% } %>
}
@m1ga I've added a possible fix for that - a missing null-check on the classpaths
(especially for old modules who don't have the classpaths:
attribute set in the manifest file. I hope optional chaining is supported in the CLI 😇
Not sure if that also fixes the hyperloop build, but as the other statement has thrown before generating the correct file, it could fix it as well.
// Crashed here
buildGradleContent = ejs.render(buildGradleContent.toString(), {
classpaths: this.manifest.classpaths?.split(',') ?? [],
});
// Never reached this code because of the crash, resulting in a template-based gradle file
await fs.writeFile(path.join(this.buildDir, 'build.gradle'), buildGradleContent);
@m1ga I've added a possible fix for that - a missing null-check on the
classpaths
(especially for old modules who don't have theclasspaths:
attribute set in the manifest file. I hope optional chaining is supported in the CLI 😇Not sure if that also fixes the hyperloop build, but as the other statement has thrown before generating the correct file, it could fix it as well.
// Crashed here buildGradleContent = ejs.render(buildGradleContent.toString(), { classpaths: this.manifest.classpaths?.split(',') ?? [], }); // Never reached this code because of the crash, resulting in a template-based gradle file await fs.writeFile(path.join(this.buildDir, 'build.gradle'), buildGradleContent);
@hansemannn I'll go over this, and the review @m1ga asked for.