nordnet / cordova-universal-links-plugin

[DEPRECATED] - Cordova plugin to support Universal/Deep Links for iOS/Android.
https://github.com/nordnet/cordova-universal-links-plugin/issues/160
MIT License
348 stars 531 forks source link

android:autoVerify breaks android lower than 5.0 #53

Closed aszmyd closed 8 years ago

aszmyd commented 8 years ago

Because of this change: https://github.com/nordnet/cordova-universal-links-plugin/pull/42 my build breaks complaining about "No resource identifier found for attribute 'autoVerify' in package 'android'" which means i have too low android platform (4.0.2). I've tried 4.1.1 but the same result.

Looks like the android:autoVerify attribute has been added on API 23 which is supported by Android >= 5.

So this change is so breaking (for everyone on android < 5) that it shouldnt be a patch release!

nikDemyankov commented 8 years ago

That error can occur during compilation, if you are compiling with old sdk. In case if you are using the new one - this tag is just ignored for older devices and compilation is successful.

Just checked this with the following:

  1. Create new android project:

    cordova create Test
    cd ./Test
    cordova platform add android
    cordova plugin add cordova-universal-links-plugin
  2. Added universal links info into config.xml:

    <universal-links>
     <host name="example.com" scheme="https">
       <path url="/path/*" />
     </host>
    </universal-links>
  3. Build and run:

    cordova build android
    cordova run android

Project builded and ran properly on Android 4.1.

So try to:

  1. Download latest SDK thru the SDK Manager.
  2. Update your Cordova android platform to 5.1.1.
se1exin commented 8 years ago

I am also getting the error:

No resource identifier found for attribute 'autoVerify' in package 'android'

Relevant lines in config.xml:

<preference name="android-minSdkVersion" value="19"/>
<preference name="android-targetSdkVersion" value="22"/>

And heres the complete compile command:

/Users/username/Library/Android/sdk/build-tools/23.0.2/aapt package -f --no-crunch -I /Users/username/Library/Android/sdk/platforms/android-22/android.jar -M /Users/username/path/to/project/platforms/android/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /Users/username/path/to/project/platforms/android/build/intermediates/res/debug -A /Users/username/path/to/project/platforms/android/build/intermediates/assets/debug -m -J /Users/username/path/to/project/platforms/android/build/generated/source/r/debug -F /Users/username/path/to/project/platforms/android/build/intermediates/res/resources-debug.ap_ --debug-mode --custom-package com.package.name -0 apk --output-text-symbols /Users/username/path/to/project/platforms/android/build/intermediates/symbols/debug

se1exin commented 8 years ago

OK I got I just got it working by changing the following in platforms/android/project.properties:

target=android-23

Although I had already tried changing android-targetSdkVersion to 23 with no luck, manually editing this file worked.

Can this be made into a hook or something? (sorry, I'm not at all familiar with how Cordova generates the build settings files)

nikDemyankov commented 8 years ago

targetSdk and compileSdk are different things. A good explanation can be found here.

After some additional digging in the cordova's gradle file found the following lines:

// trying to determine compile sdk version from the external settings
if (!project.hasProperty('cdvCompileSdkVersion')) {
    cdvCompileSdkVersion = null;
}

// if failed - take it from the project.properties file
if (ext.cdvCompileSdkVersion == null) {
    ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
}

// compile with the detected sdk version
compileSdkVersion cdvCompileSdkVersion

As I understand, in your project you didn't set any external settings for the android project (step 1), and it uses your project.properties file preferences. These preferences are generated, when platform is added to your Cordova project. And probably they are kind of low (maybe you are using older cordova android version, don't know).

So to tell Cordova to use the correct compile version - you can look into this documentation and set cdvCompileSdkVersion to android-23.

Can this be made into a hook or something?

Yes, that can be done with the hook. But I don't think it is needed, since the solution is to just provide correct settings to the android project. And this can be done, as described in Cordova documentation.

Also, I think it will go away if you remove the old platform and install the new one:

cordova platform remove android
cordova platform add android@5.1.1
se1exin commented 8 years ago

Awesome! Thank you for such a detailed reply. No doubt will help others as well

aszmyd commented 8 years ago

@nikDemyankov Thanks, adding new cordova-android (5.1.1) helped here. Sorry for making an alert but i needed to understand the SDK versions relations better. Now i get it well :)

nikDemyankov commented 8 years ago

Good :) Happy to help.