Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

(feature-request): Capacitor Build Steps #20

Closed
AdlerJS opened this issue Jul 22, 2021 · 2 comments
Closed

(feature-request): Capacitor Build Steps #20

AdlerJS opened this issue Jul 22, 2021 · 2 comments
Labels

Comments

@AdlerJS
Copy link
Contributor

AdlerJS commented Jul 22, 2021

Hey man first just wanted to say thanks for the plugin. After evaluating over 5 different ones this one was the only one that had all the features required for our app. I was able to set it up and get it working but when running through our build pipeline the npx cap sync seems to overwrite the Android stuff. I did some digging and found your issues on Capacitor:

ionic-team/capacitor#4426
ionic-team/capacitor#4739

I was wondering if you could clarify the steps you added to get this plugin to run in a CI pipeline. Thanks!

@AdlerJS AdlerJS added the triage label Jul 22, 2021
@EinfachHans
Copy link
Owner

Hi @danbunkr 😊

The Problem here is that Cordova Plugins in Capacitor are mapped under the capacitor-cordova-android-plugins module and this has no kotlin support yet (i created PR ionic-team/capacitor#4536 to add this support).

In this PR you can see the changes that are needed in the module's build.gradle to make it work, but sadly this file is every time resettet if a capacitor update is executed (which uns on sync automatically).

So i created another PR (that you linked) that adds hook support for Capacitor CLI, so i can make the required changes via a script. I did this and my Appflow Builds now works perfect.

Add a script in package.json:

{
  "scripts": {
    ...
    "capacitor:sync:after": "node scripts/fix-capacitor-android-plugins-kotlin-version.js"
    ...
  }
}

the script file:

const fs = require("fs");

if (process.env.CAPACITOR_PLATFORM_NAME === 'android') {
  let file = fs.readFileSync('./android/capacitor-cordova-android-plugins/build.gradle', 'utf8');

  file = file.replace(/apply plugin: 'com.android.library'\n\s*\n/, `apply plugin: 'com.android.library'\r\nif(project.hasProperty('kotlin_version')) {\r\n    apply plugin: 'kotlin-android'\r\n}\r\n\r\n`);
  file = file.replace(/implementation "org.apache.cordova:framework:\$cordovaAndroidVersion"\n[ ]{4}\/\/ SUB-PROJECT DEPENDENCIES START/,
    `implementation "org.apache.cordova:framework:$cordovaAndroidVersion"\r\n    if(project.hasProperty('kotlin_version')) {\r\n        implementation "androidx.core:core-ktx:+"\r\n        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"\r\n    }\r\n    // SUB-PROJECT DEPENDENCIES START`);

  fs.writeFileSync('./android/capacitor-cordova-android-plugins/build.gradle', file);
}

@AdlerJS
Copy link
Contributor Author

AdlerJS commented Jul 23, 2021

@EinfachHans thanks for the reply! I will look into implementing this in our pipeline. We ended up solving it by doing something similar where we have the android build.gradle file that was working locally stored in the project and then after the build pipline runs npx cap sync we run a basic node script that just replaces the build.gradle file. It works but I actually like your solution better

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants