Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordova-build-override does not override for Android #5840

Closed
horner opened this issue Dec 20, 2015 · 16 comments
Closed

cordova-build-override does not override for Android #5840

horner opened this issue Dec 20, 2015 · 16 comments

Comments

@horner
Copy link
Contributor

horner commented Dec 20, 2015

Create a cordova-build-override/platforms/android/build-extras.gradle
Then run:

$ meteor reset
$ meteor build --server --verbose
....
Processing mobile-config.js
Writing new config.xml
Creating Cordova project
% Creating a new cordova project.
Preparing Cordova project from app bundle
Processing mobile-config.js
Copying resources for mobile apps
Writing new config.xml
Copying over the cordova-build-override directory
Adding platform iOS to Cordova project
% Adding ios project...
Adding plugin cordova-plugin-camera@1.2.0 to Cordova project
% Fetching plugin "cordova-plugin-camera@1.2.0" via npm
% Installing "cordova-plugin-camera" for android
% Failed to install 'cordova-plugin-camera':CordovaError: The provided path ".meteor/local/cordova-build/platforms/android" is not an Android project.

While processing a clean build (ie: meteor reset) this error occurs, because the platform directory exists but it empty. It appears that the directory is copied over to the destination before the builder.copyBuildOverride() operation is done. The order should be reversed, per documentation: https://github.com/meteor/meteor/wiki/Meteor-Cordova-integration#advanced-build-customization

Others have issues too: #5373

I developed a pull request with a possible fix, but is has not been accepted. #5792

@timbotnik
Copy link

Thanks for the PR @horner. We'll take a look.

@varunwyest
Copy link

Any update on this, we are having similar issue

@horner
Copy link
Contributor Author

horner commented Jan 16, 2016

@martijnwalraven accepted the PR #5792 on Jan 7th. In the meantime, I rename the cordova-build-override, build, then put it back and build again... but only after a reset. It's a lot of extra work but it gets it done.

@madc0w
Copy link

madc0w commented Feb 11, 2016

We are experiencing a similar issue here. Our "meteor build" command fails to take our cordova-build-override/AndroidManifest.xml . We've tried copying this file to .meteor/local/cordova-build/platforms/android before the build ... but to no avail.

Can you please provide some guidance on exactly what steps should be taken to ensure that the AndroidManifest.xml file is properly included in the APK?

Also, how can we easily verify that it has been copied? Under the build directory, should we be lookinig at /android/project/CordovaLib/AndroidManifest.xml, or android/project/AndroidManifest.xml ... or both? or some other place?

Thanks for any assistance you can provide!

@martijnwalraven
Copy link
Contributor

I'm looking at possible changes to the cordova-build-override mechanism, so I'm wondering how people are currently using it.

Why do you feel you need to modify AndroidManifest.xml or build-extras.gradle manually?

@madc0w
Copy link

madc0w commented Feb 19, 2016

Thanks for the reply.

We are trying to use a Cordova plugin for Mixpanel: https://github.com/samzilverberg/cordova-mixpanel-plugin . This plugin is only a wrapper around native functionality. It seems that we are required to modify permissions in AndroidManifest.xml in order to make Mixpanel push notifications work properly. See https://mixpanel.com/help/reference/android#push_init

@madc0w
Copy link

madc0w commented Mar 10, 2016

The inability to override AndroidManifest.xml continues to be a major issue for us. We are now confronted with the same problem trying to integrate Branch.io. Is there any workaround to this issue?

See
http://stackoverflow.com/questions/35914927/using-branch-io-with-meteor

Specifically:

meteor build --verbose builddir --server=server
...
/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:62: error: No resource identifier found for attribute 'autoVerify' in package 'android'

:processReleaseResources FAILED

FAILURE: Build failed with an exception.

AndroidManifest.xml line 62 is cited as the source of the problem no matter how we change cordova-build-override/AndroidManifest.xml.

@madc0w
Copy link

madc0w commented Mar 10, 2016

Here is where things stand:

Added to the top of cordova-build-override/config.xml (which is actually taken):

<hook type="before_run" src="hooks/before_run.sh" />
<hook type="before_compile" src="hooks/before_compile.sh" />
<hook type="before_build" src="hooks/before_build.sh" />
<hook type="before_prepare" src="hooks/before_prepare.sh" />
<hook type="after_compile" src="hooks/after_compile.sh" />
<hook type="after_build" src="hooks/after_build.sh" />
<hook type="after_prepare" src="hooks/after_prepare.sh" />

Each of these hook scripts looks exactly the same :

#!/bin/bash
echo AFTER_BUILD
cp ~/projdir/cordova-build-override/AndroidManifest.xml ~/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release

Then:

chmod a+x projdir/hooks/*
cp -R ~/projdir/hooks ~/projdir/.meteor/local/cordova-build/

We see that the scripts are properly executed when we do:

meteor build --verbose builddir --server=$server

but STILL the same error is displayed from the original, unaltered AndroidManifest.xml file, indicating that we have still not managed to copy this file at the right time during the build.

Here is the output:

Building Cordova app for platform Android
% Running command: /home/mad/projdir/.meteor/local/cordova-build/hooks/before_build.sh /home/mad/projdir/.meteor/local/cordova-build
BEFORE_BUILDCordova app for Android [==========================] 100% 0.0s

% Running command: /home/mad/projdir/.meteor/local/cordova-build/hooks/before_prepare.sh /home/mad/projdir/.meteor/local/cordova-build
BEFORE_PREPARErdova app for Android -

% Running command: /home/mad/projdir/.meteor/local/cordova-build/hooks/after_prepare.sh /home/mad/projdir/.meteor/local/cordova-build
AFTER_PREPAREordova app for Android |

% Running command: /home/mad/projdir/.meteor/local/cordova-build/hooks/before_compile.sh /home/mad/projdir/.meteor/local/cordova-build
BEFORE_COMPILErdova app for Android |

% Running command: /home/mad/projdir/.meteor/local/cordova-build/platforms/android/cordova/build --release
ANDROID_HOME=/home/mad/Android/Sdkd /
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Running: /home/mad/projdir/.meteor/local/cordova-build/platforms/android/gradlew cdvBuildRelease -b /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build.gradle -Dorg.gradle.daemon=true

Configuring > 0/2 projects > root project > Resolving dependencies ':classpath'
:preBuild
:preReleaseBuild
:checkReleaseManifest
:CordovaLib:compileLint

...

/home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:51: error: No resource identifier found for attribute 'autoVerify' in package 'android'

/home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:75: error: No resource identifier found for attribute 'autoVerify' in package 'android'

:processReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':processReleaseResources'.

    com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /home/mad/Android/Sdk/build-tools/23.0.1/aapt package -f --no-crunch -I /home/mad/Android/Sdk/platforms/android-22/android.jar -M /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml -S /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/res/release -A /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/assets/release -m -J /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/generated/source/r/release -F /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/res/resources-release.ap_ --custom-package com.appname -0 apk --output-text-symbols /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/symbols/release
    Error Code:
    1
    Output:
    /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:51: error: No resource identifier found for attribute 'autoVerify' in package 'android'

    /home/mad/projdir/.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:75: error: No resource identifier found for attribute 'autoVerify' in package 'android'

@martijnwalraven
Copy link
Contributor

It seems the error No resource identifier found for attribute 'autoVerify' in package 'android' occurs because it requires Android SDK version 23, and the Cordova version integrated in Meteor 1.2 uses version 22.

Could you try this with Meteor 1.3 beta, which uses Android SDK version 23?

There is also an issue with the cordova-build-override mechanism that was fixed in Meteor 1.3. But in general, the override mechanism is much too course grained to be of use, and we'll be deprecating it. By replacing the whole AndroidManifest.xml, you're ignoring all settings generated by Cordova, like permissions required by installed plugins. A better solution is to use a custom Cordova plugin with a <config-file> entry modifying the generated AndroidManifest.xml in its plugin.xml.

@madc0w
Copy link

madc0w commented Mar 11, 2016

Thanks for all that useful info!

So, first I tried:

$ meteor update --release 1.3-modules-beta.8

$ meteor --version
Meteor 1.3-modules-beta.8

This had no impact. The build still gives the same error, same line number, so it appears that my AndroidManifest.xml override is STILL not being taken.

I'll be rolling back to 1.2.1 and diving into writing a custom Cordova plugin now, as you suggest....

@madc0w
Copy link

madc0w commented Mar 11, 2016

So I've created a Cordova plugin project with a single file in it: plugin.xml, as you suggested. I've now spent a good hour trying to understand how to add this plugin to my project. I've tried many variations of "meteor add cordova: ...", but nothing has worked so far. Sometimes, the command pretends to work, and I see something added when I do "meteor list", but then nothing changes in the build. Other times, I am told "Meteor requires either an exact version (e.g. https://marcadonis@1.0.0), a Git URL with a SHA reference, or a local path." I would be happy to add the plugin from a local path... but I can find no documentation on how to accomplish this.

Is "meteor add" documented somewhere?

See http://stackoverflow.com/questions/35938360/add-cordova-plugin-to-meteor-from-local-path

@martijnwalraven
Copy link
Contributor

To add a plugin called my-plugin from a local path that is the parent directory of the app directory, meteor add cordova:my-plugin@file://../my-plugin should work.

@madc0w
Copy link

madc0w commented Mar 11, 2016

Wow... that actually worked! Thanks for that!
I now see a modified version of AndroidManifest.xml under .meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/ , which includes the changes I specified in plugin.xml... just like you said.

BUT

There's a big problem with this approach. According to the Cordova plugin docs here:
https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html

"The config-file element only allows you to append new children to an XML document tree."

This is no good, as I still have the same issue with autoVerify due to the fact that I can't replace the offending bit, which is:

        <intent-filter android:autoVerify="true" >
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="bnc.lt"
                android:pathPrefix="/ "
                android:scheme="https" />
        </intent-filter>

Resulting in the same old error:

.meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release/AndroidManifest.xml:73: error: No resource identifier found for attribute 'autoVerify' in package 'android'

(but at a new line number! Hooray!)

My own version of this section is correctly inserted into the file, but this bad old code remains.
Looking through the docs for plugin.xml, the only way I can see to replace code might be use resource-file instead, which would replace the whole file... but that puts us back to having to maintain the entire AndroidManifest.xml by hand.

Any other ideas??

Thanks so much for your help getting this far!

@madc0w
Copy link

madc0w commented Mar 11, 2016

resource-file doesn't seem to be the answer, either. The problem might be that I don't know what "target" to set. I have:

    <resource-file src="AndroidManifest.xml" target="platforms/android"/>

... but my AndroidManifest.xml is not taken in the build. I've tried various locations for "target", including "", "/", "/platforms/android", and variations on ".meteor/local/cordova-build/platforms/android/build/intermediates/manifests/full/release". All of these fail in various ways.

So... still searching for a way to override the generated erroneous AndroidManifest.xml .

@crazybaud
Copy link

I'm looking at possible changes to the cordova-build-override mechanism, so I'm wondering how people are currently using it.

@martijnwalraven, it was not working so we used this workaround #7693 in our case.

@hwillson
Copy link
Contributor

PR #5792 was merged to fix the original issue. If there are other related problems here, please consider opening them in new issues. Closing - thanks!

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

No branches or pull requests

7 participants