apache / cordova-paramedic

Apache Cordova - Paramedic
https://cordova.apache.org/
Apache License 2.0
36 stars 53 forks source link

Ability to customise generated cordova project #197

Closed l0stpenguin closed 4 years ago

l0stpenguin commented 4 years ago

Feature Request

I am currently implementing testing for my plugin cordova-plugin-background-upload using cordova paramedic on Travis. But it lacks the ability to customise the generated project, more specifically overriding the minSdk version for android.

Motivation Behind Feature

The plugin depends on a native android library (android-upload-service) which i am upgrading. the issue is that the library needs a minimum android sdk version of 21 but the generated cordova project hardcodes it to 19. This is usually solved by setting android-minSdkVersion in the project config.xml:

<preference name="android-minSdkVersion" value="21" /> Since i do not have access to the generated cordova project, i can't set it as required. Hence the build fails completely:

/tmp/tmp-5184gAFMCOMFnpok/platforms/android/app/src/main/AndroidManifest.xml Error:
    uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [net.gotev:uploadservice-okhttp:4.0.0-rc2] /home/travis/.gradle/caches/transforms-1/files-1.1/uploadservice-okhttp-4.0.0-rc2.aar/4fd93cca550e81e4d68695d2277fa064/AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
    or increase this project's minSdk version to at least 21,
    or use tools:overrideLibrary="net.gotev.uploadservice.okhttp" to force usage (may lead to runtime failures)

Complete log of the build can be accessed here: https://travis-ci.org/spoonconsulting/cordova-plugin-background-upload/jobs/633747584

Feature Description

Having a config parameter like cordova-config-path pointing to the location of a normal cordova config.xml would be helpful. This would be merged with the generated one and hence allowing customisation.

Alternatives or Workarounds

I currently have not found any workaround to fix this issue. Is there something i can do to allow the plugin to be built?

breautek commented 4 years ago

The may work?

Untested, but should be something like:

<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
    <uses-sdk android:minSdkVersion="21" />
</edit-config>

Also note that, I think that way of defining minSdkVersion is deprecated, I think you're suppose to define it via gradle instead, but not 100% sure on that detail.

l0stpenguin commented 4 years ago

@breautek I tried your solution but the build failed with an error: unable to graft /manifest/uses-sdk from xml

So i changed the value via a custom gradle reference by using the following gradle file and it worked:

def minSdkVersion = 21

if(cdvMinSdkVersion == null) {
    ext.cdvMinSdkVersion = minSdkVersion;
} else if (cdvMinSdkVersion.toInteger() < minSdkVersion) {
    ext.cdvMinSdkVersion = minSdkVersion;
} 

And my main plugin.xml:

 <platform name="android">
       <framework src="test.gradle" custom="true" type="gradleReference"/>
 </platform>

Adding to the test plugin.xml did not seem to work, so had to add directly in the main plugin.