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

[CLI] Allow to use android libraries during build #4935

Closed

Conversation

farfromrefug
Copy link
Contributor

Those libs can have res, which is the whole point.

I put actionbarsherlock as a commented example

… which is the whole point.

I put actionbarsherlock as a commented example
@cb1kenobi
Copy link
Contributor

You can actually do this today using CLI hooks. Try:

exports.init = function (logger, config, cli) {
    cli.on('build.android.aapt', {
        pre: function (data, next) {
            data.args.push('--auto-add-overlay');

            var externalLibraries = [ /* ... */ ];

            externalLibraries.forEach(function (lib) {
                data.args.push('--extra-packages', lib.javaClass, '-S', lib.resPath);
            });

            next(data);
        }
    });
};

As for the scanning of Java files in the gen and src dirs, I've changed it so that it scans at the root of the gen folder instead of the gen/com.mycomany.myapp dir. Stay tuned.

@cb1kenobi cb1kenobi closed this Nov 14, 2013
@farfromrefug farfromrefug deleted the android_build_external_libs branch November 14, 2013 08:45
@farfromrefug
Copy link
Contributor Author

waiting for your commit, then i ll use your hook then

@mokesmokes
Copy link
Contributor

Referencing this Jira issue: https://jira.appcelerator.org/browse/TIMOB-11360
Can we please have, as part of the commit, clear instructions on:

  1. How to add libs with external XML resources to Titanium Android modules
  2. How to add libs with external XML resources to the Titanium core
    Thanks.

@cb1kenobi
Copy link
Contributor

@farfromrefug FYI, the gen dir change landed today.

@farfromrefug
Copy link
Contributor Author

Done it Chris!
I used your method to create a hook to build actionbarsherlock. It was dead easy!!!!
As a reference i just had to modify your example a little

exports.init = function(logger, config, cli) {

    cli.on('build.android.aapt', {
        pre: function(data, next) {
            var args = data.args[1];
            args.push('--auto-add-overlay');

            var externalLibraries = [{
                javaClass:'com.actionbarsherlock',
                resPath:path.join(this.platformPath, 'externals', 'actionbarsherlock/res')
            }];

            externalLibraries.forEach(function(lib) {
                args.push('--extra-packages', lib.javaClass, '-S', lib.resPath);
            });

            next(data);
        }
    });
};

@cb1kenobi
Copy link
Contributor

Doh, forgot that data.args[1] is the params. :) Glad you got it working.

@jbaquero
Copy link

Hello, I had successfully used the approach described here on my project, with version 3.2.0

This is, adding a plugin, with a hook folder and inside that hook:

/**
 * This code is needed to copy the resources of the GUJ EMS library project when compiling the Android apk.
 * 
 * It's due to a Titanium bug on the building process explained here: https://jira.appcelerator.org/browse/TIMOB-11360
 *
 */

exports.cliVersion = '>=3.X';

exports.init = function (logger, config, cli, appc) {
    cli.on('build.android.aapt', {

        pre: function(data, next) {
            var args = data.args[1];
            args.push('--auto-add-overlay');
            var externalLibraries = [
                {
                    javaClass:'CLASS NAME',
                    resPath:'RESOURCES FOLDER'
                }
            ];

            externalLibraries.forEach(function(lib) {
                args.push('--extra-packages', lib.javaClass, '-S', lib.resPath);
            });

            next(data);
        }

    });
};

I got it working perfectly, I was able to use my module which was using an Android library with resources, etc.

Now I have upgraded to 3.2.1 and I can't compile for Android anymore:

[INFO] : Generating /Users/Jose/Documents/Titanium_Studio_Workspace/HomestylrTest/build/android/res/values/theme.xml
[ERROR] : Project failed to build after 9s 20ms
[ERROR] Application Installer abnormal process termination. Process exit value was 1

If I remove the plugin, it compiles normally again, but of course the module fails because the resources are not present.

Do you have any idea why it doesn't work anymore? Is that solution no valid anymore in 3.2.1 ? Can I revert the CLI, IDE, etc. easily to get it working again?

Thanks in advance!!

@farfromrefug
Copy link
Contributor Author

Yes that error is due to the very latest CLI. To me ti's the call to next with "data" that was the source of the error.
Call "next();" and you should be fine

@cb1kenobi
Copy link
Contributor

If I recall correctly, cli.version == '3.2.0', then do next(data), otherwise do next(null, data).

@farfromrefug
Copy link
Contributor Author

Oh that s the null then! Though it works without arguments because what you modify in the hook is a reference object ;)
Thanks Chris!

@jbaquero
Copy link

jbaquero commented Mar 3, 2014

Thanks a million!! It works like a champ now ;-)

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

Successfully merging this pull request may close these issues.

None yet

4 participants