pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 587 forks source link

Non-instantiated variable "ANDROID_SUPPORT_VERSION" in build.gradle since version 2.1.0, causing "Could not get unknown property 'ANDROID_SUPPORT_V4_VERSION'" #240

Closed Bernhard-Steindl closed 5 years ago

Bernhard-Steindl commented 5 years ago

Expected Behaviour

When invoking the following command

cordova plugin add cordova-plugin-file-opener2  --variable ANDROID_SUPPORT_VERSION=26.+

before adding an android cordova platform, the variable ANDROID_SUPPORT_VERSION should be set according to the passed argument (here 26.+) in the build.gradle resp. for the platform plugin.

In the platforms/android/build.gradle there should be (as in version 2.0.19):

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: "CordovaLib"))
    compile "com.android.support:support-v4:26.+"

instead of a non-instantiated variable ANDROID_SUPPORT_V4_VERSION

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: "CordovaLib"))
    compile "com.android.support:support-v4:$ANDROID_SUPPORT_V4_VERSION"

The plugins/cordova-plugin-file-opener2/plugin.xml has changed between these versions as follows.

Since version 2.1.0

<preference name="ANDROID_SUPPORT_V4_VERSION" default="27.+"/>
<framework src="com.android.support:support-v4:$ANDROID_SUPPORT_V4_VERSION"/>

in version 2.0.19

<framework src="com.android.support:support-v4:+" />

Actual Behaviour

Our build for our cordova app fails, because of an update from cordova-plugin-file-opener2 version 2.0.19 to 2.1.0. The lower version works just fine, but 2.1.0 not.

In the build.gradle file the variable ANDROID_SUPPORT_VERSION is not instantiated with a value, when invoking

cordova plugin add cordova-plugin-file-opener2  --variable ANDROID_SUPPORT_VERSION=26.+

The non-instantiated variable leads to the following build error for us

15:33:38 FAILURE: Build failed with an exception.
15:33:38 
15:33:38 * Where:
15:33:38 Build file '/Users/dummy/workspace/project/platforms/android/build.gradle' line: 261
15:33:38 
15:33:38 * What went wrong:
15:33:38 A problem occurred evaluating root project 'android'.
15:33:38 > Could not get unknown property 'ANDROID_SUPPORT_V4_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

because of the line compile "com.android.support:support-v4:$ANDROID_SUPPORT_V4_VERSION" in the build.gradle since the new version.

Reproduce Scenario

delete plugins folder and platforms folder invoke in terminal

cordova plugin add cordova-plugin-file-opener2  --variable ANDROID_SUPPORT_VERSION=26.+

and then

ionic cordova platform add android@6.4.0

Check platforms/android/build.gradle under dependency for an non-instantiated variable ANDROID_SUPPORT_VERSION.

Our config.xml contains:

<plugin name="cordova-android-support-gradle-release" spec="1.3.0">
    <variable name="ANDROID_SUPPORT_VERSION" value="26.+" />
</plugin>
<plugin name="cordova-plugin-file-opener2" spec="2.1.0" />
    <variable name="ANDROID_SUPPORT_V4_VERSION" value="26.+" />
</plugin>

Platform and Version

Android SDK Tools:     25.2.5
ionic (Ionic CLI):     3.20.0
Node version:          8.11.3
cordova (Cordova CLI): 6.5.0 

Plugin version

cordova-plugin-file-opener2 2.1.0 "File Opener2"

Update: Corrected Typo of plugin version from 2.0.21 to 2.1.0.

shnist commented 5 years ago

@Bernhard-St, thanks for raising this issue and for taking the time to add all of this detail. I think I can help you out.

Firstly, version 2.0.21 doesn't exist, there is only 2.0.19 and 2.1.0. Version 2.1.0 introduced the new variable around the android support version, but requires Cordova CLI 7 or newer (see https://github.com/pwlin/cordova-plugin-file-opener2/issues/238). Unfortunately we were unaware of the incompatibility with Cordova CLI 6, otherwise we would have done a major release instead.

Secondly, your issue has helped to identify a typo in the README, as the name of the variable in the example was wrong. It should be ANDROID_SUPPORT_V4_VERSION not ANDROID_SUPPORT_VERSION. I will be releasing a patch release to fix this for both github and npm today.

Anyway, a couple of suggested ways to fix the issue.

If you can upgrade to Cordova CLI 7 or newer then you can do that and install version 2.1.0 of the plugin.

If you can't upgrade your Cordova CLI then stick to version 2.0.19 of the plugin, which does not have the variable, but the cordova-android-support-gradle-release should help keep the support versions consistent for your project.

Let me know how you get on.

Bernhard-Steindl commented 5 years ago

@shnist, Thank you for your response to my reported issue and your support. As you pointed out, I incorrectly stated the wrong version. I changed the version in my issue description, accordingly.

Unfortunately, I cannot upgrade at the moment, so I will stick to Cordova CLI 6.5.0 and version 2.0.19 of the cordova-plugin-file-opener2 plugin.