2

I want to add a native (integration test) module to a Cordova Android project.

For fully native projects, you just add a new module, commit and be done with it. But for Cordova I of course don't really want to mess with the generated Android project as some of these changes might be lost on build etc.

I got a Poof of Concept of the module working manually by having the module folder outside of the Cordova Android folder and adding this to settings.gradle:

include ':module-androidTest'
project(':module-androidTest').projectDir = new File("../module-tests")

But of course line 1 of that file already says

// GENERATED FILE - DO NOT EDIT

Is there any other way to add additional modules to a Cordova Android project?


Some approaches I researched or thought about:

  • Can I somehow do this with build-extras.gradle? (I don't think so as settings.gradle is several steps before build-extras and build.gradle, right?)

  • Older StackOverflow questions suggest manually editing a GradleBuilder.js file: https://stackoverflow.com/a/35504783/252627 But of course this would get lost each time I completely generate a new Cordova project. Not a good idea, correct?

  • Can I maybe work around this somehow via a Cordova plugin? I know these can load frameworks etc - maybe also a module somehow?

janpio
  • 10,645
  • 16
  • 64
  • 107
  • I think what you are looking for can be done using a custom plugin which can extend the base gradle config using a framework tag like this: ``. – David Oct 03 '17 at 23:43
  • Thanks for the idea @David, but `gradleReference` "only" allows you to add additional stuff to your `build.gradle` file between the `// PLUGIN GRADLE EXTENSIONS START // PLUGIN GRADLE EXTENSIONS END` lines of the generated `build.gradle` (which is awesome, but doesn't help me, correct?) – janpio Oct 04 '17 at 09:41
  • Well I don't know if it helps you in your specifiy use-case which is why I added it as a comment but this is how you usually extend the cordova android project. – David Oct 04 '17 at 19:13
  • Please post it as an answer, so I can potentially accept it if this turns out to work. – janpio Oct 06 '17 at 13:36

1 Answers1

1

I think what you are looking for can be done using a custom plugin which can extend the base gradle config using a framework tag like this:

<framework src="relative/path/to/your/gradlefile/*.gradle" custom="true" type="gradleReference" />

This is how a cordova-android project is usually extended.

David
  • 7,387
  • 3
  • 22
  • 39