cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Ginchereau <jason...@microsoft.com>
Subject RE: Proposal: Change Android Project Directory Structure to Android Studio style
Date Thu, 02 Jun 2016 22:37:45 GMT
Joe,
As we discussed on the call yesterday, I wrote a script that transforms a Cordova plugin's
android platform to a module structure:

https://github.com/jasongin/cordova-plugin-compat/blob/master/scripts/Modularize.js

The transformation to a module includes:
 * Generation of build.gradle for the plugin module
    - Referencing a custom gradle file from the plugin if specified in plugin.xml
    - Referencing dependency plugins if specified in plugin.xml
 * Generation of AndroidManifest.xml for the plugin module
    - Including config-file transformations specified in plugin.xml for AndroidManifest.xml
    - (The contents of the module's AndroidManifest.xml get automatically merged into the
app at build time.)
 * Copying source files and resources to correct subdirectories within the module
    - Remapping to the directory structure preferred by Android Studio: src/main/java and
src/main/res

I verified with several real plugins in a test app project that the result builds successfully,
after you also reference the plugins' modules in the application root settings.gradle.

The script depends on some things in cordova-common, though I have not included a package.json
that specifies that dependency; you'll have to `npm install cordova-common` explicitly if
you want to try it out.

There are some TODOs in the code for things that would be required to make the solution more
complete. And probably I have forgotten some things, which could be found by testing with
more plugins. But it's a good start. While I put it in (my fork of) cordova-plugin-compat,
that is just temporary for lack of a better place. I haven't done any work to integrate this
kind of transformation into cordova-android plugin installation code, as was suggested on
the call.

Please note I'm not planning to do any more work on this feature. I hope someone else can
pick this up and build on this idea, so that cordova-android can maintain compatibility with
lots of 3rd-party plugins that might not get updated anytime soon.

Jason


-----Original Message-----
From: Jesse [mailto:purplecabbage@gmail.com] 
Sent: Wednesday, June 1, 2016 4:28 PM
To: dev@cordova.apache.org
Subject: Re: Proposal: Change Android Project Directory Structure to Android Studio style

The newer version of push is here [1]  and it would break also, we can discuss this more in
the hangout.

Also, note that it is not 20k references, but more like 2k ;)

[1] https://github.com/phonegap/phonegap-plugin-push


@purplecabbage
risingj.com

On Tue, May 31, 2016 at 2:56 PM, Frederico Galvão < frederico.galvao@pontoget.com.br>
wrote:

> I know it's only a detail, but
> https://github.com/phonegap-build/PushPlugin,
> the example used as a plugin that would "break", is a deprecated and 
> old plugin.
>
> 2016-05-31 13:46 GMT-03:00 Nikhil Khandelwal <nikhilkh@microsoft.com>:
>
> > It sounds like you are working on a plan to remap the older 
> > directory structure to a new one. Will look forward to updates on 
> > the design and
> code
> > for that. In that case our expectation is that most plugins will not
> break
> > - is that correct? It will be great to do some compat testing with 
> > say
> the
> > top plugins.
> >
> > I understand it's hard to guarantee complete compat and we need to 
> > move forward but breaking the entire plugin ecosystem will cause a 
> > lot of
> issues
> > for existing Cordova developers.
> >
> > -Nikhil
> >
> > -----Original Message-----
> > From: Joe Bowser [mailto:bowserj@gmail.com]
> > Sent: Tuesday, May 31, 2016 8:22 AM
> > To: dev <dev@cordova.apache.org>
> > Subject: Re: Proposal: Change Android Project Directory Structure to 
> > Android Studio style
> >
> > On Fri, May 27, 2016 at 12:22 PM, Nikhil Khandelwal < 
> > nikhilkh@microsoft.com>
> > wrote:
> >
> > > As I see it, a change to the directory structure will break almost 
> > > every Android plugin currently out there.
> > >
> > >
> > I know.  However, I don't think that's a good enough reason to not 
> > do
> this.
> >
> >
> > > There are atleast 20K references [1] on github where people use 
> > > depend on the current directory structure for android: "res/xml/config.xml".
> > >
> > > Taking the example of a config.xml manipulation that will now stop
> > working:
> > > https://github.com/phonegap-build/PushPlugin/blob/master/plugin.xm
> > > l#L3
> > > 4
> > >
> > > Can you explain how source-file and other tags that reference path 
> > > will continue to work? Looking at your current branch [2] there 
> > > are not changes to path old path references in plugin.xml to new path.
> > >
> >
> > Actually, here's the thing.  They won't.  We're going to have to fix 
> > our tooling so that they remap.  After working on the exploratory 
> > branch, all our plugin installation code is stuck in plugman and 
> > really should be handled by the platforms so that we can actually 
> > handle changes to
> Android
> > Studio and Xcode.
> >
> > What I'm now proposing is that by default when we specify a source 
> > file, or a config file without specifying a target, it by default 
> > goes to a location specified by the project.  That means that when 
> > you are using an Android Studio project, it knows that we keep the 
> > config.xml in a
> different
> > location than the old project.  That way, if Google decides that 
> > they
> don't
> > like the current Android Studio project structure and they decide to
> change
> > things again, we're not stuck holding the bag for years and being 
> > stuck having to do all this work so that we can actually allow 
> > native
> developers
> > to be able to use Cordova, since it's almost completely unusable to 
> > these developers currently.
> >
> >
> > >
> > > If the path of the file changes it will break lots of plugins and 
> > > if the plugins change to work with the new directory structure 
> > > they will not work with older versions of Cordova. Let me know if 
> > > I missed some part of this change which ensures most plugins for 
> > > Android do not stop
> > working.
> > >
> > > [1]
> > > https://github.com/search?q=%22res%2Fxml%2Fconfig.xml%22+filename%
> > > 3Apl
> > > ugin.xml&ref=searchresults&type=Code&utf8=%E2%9C%93
> > > [2]
> > > https://github.com/apache/cordova-android/compare/master...infil00
> > > p:st
> > > udio_project_structure
> > >
> > >
> > > -----Original Message-----
> > > From: Joe Bowser [mailto:bowserj@gmail.com]
> > > Sent: Tuesday, May 17, 2016 8:14 PM
> > > To: dev <dev@cordova.apache.org>
> > > Subject: Re: Proposal: Change Android Project Directory Structure 
> > > to Android Studio style
> > >
> > > On Tue, May 17, 2016 at 5:35 PM, Richard Knoll 
> > > <riknoll@microsoft.com>
> > > wrote:
> > >
> > > > Does that mean the plan is to provide a mapping from old file 
> > > > locations to new ones? For example, if I have this in my plugin.xml:
> > > >
> > > >     <config-file target="res/values/strings.xml" parent="" />
> > > >
> > > > Will the new cordova-android automatically convert the target 
> > > > value to the new location of "app/src/main/res/values/strings.xml"?
> > > >
> > >
> > >
> > > I'm pretty sure that config-file targets like that won't work 
> > > properly, but I think that source, resource and assets should.  I 
> > > would have added that as a resource file, since it's strings.xml.
> > >
> > >
> > > >
> > > > Thanks,
> > > > Richard
> > > >
> > > > -----Original Message-----
> > > > From: Joe Bowser [mailto:bowserj@gmail.com]
> > > > Sent: Tuesday, May 17, 2016 3:51 PM
> > > > To: dev <dev@cordova.apache.org>
> > > > Subject: Re: Proposal: Change Android Project Directory 
> > > > Structure to Android Studio style
> > > >
> > > > @Richard: The changes to the Android files in cordova-common 
> > > > should allow for config-file, source-file and resource-file to work fine.
> > > > I already did something similar in February, but I should have 
> > > > checked it in on an Cordova-Android branch instead of the other repo.
> > > >
> > > > https://github.com/infil00p/cordova-android-studio
> > > >
> > > > @Parashuram: Does this drop the JAR is libs?  I couldn't quite 
> > > > tell from looking at the JS code doing the installation.  If it 
> > > > does, that won't change at all.
> > > >
> > > > On Tue, May 17, 2016 at 3:03 PM, Parashuram N 
> > > > <panarasi@microsoft.com>
> > > > wrote:
> > > >
> > > > > This is an example -
> > > > > https://github.com/ConnectSDK/Connect-SDK-Cordova-Plugin. This 
> > > > > actually has a hook that downloads and places the source code 
> > > > > based on the current directory structure.
> > > > >
> > > > > On 5/17/16, 2:53 PM, "Richard Knoll" <riknoll@microsoft.com>
> wrote:
> > > > >
> > > > > >We have a lot of plugin.xml elements that depend on the old 
> > > > > >file
> > > > > structure. Tags like config-file, source-file, resource-file, etc.
> > > > > all have target elements that take arbitrary paths to project
> files.
> > > > > Looking at the new project structure, it seems like most of 
> > > > > the relevant folders have moved around. Does your proposal 
> > > > > handle that or do plugins need to update to reflect the new 
> > > > > structure? I figure there isn't much we can do for plugins that use
hooks.
> > > > > >
> > > > > >Richard
> > > > > >
> > > > > >-----Original Message-----
> > > > > >From: Joe Bowser [mailto:bowserj@gmail.com]
> > > > > >Sent: Tuesday, May 17, 2016 2:07 PM
> > > > > >To: dev <dev@cordova.apache.org>
> > > > > >Subject: Re: Proposal: Change Android Project Directory 
> > > > > >Structure to
> > > > > Android Studio style
> > > > > >
> > > > > >On Tue, May 17, 2016 at 2:01 PM, Parashuram N 
> > > > > ><panarasi@microsoft.com>
> > > > > >wrote:
> > > > > >
> > > > > >> I think the proposal is great. Our gradle is pretty big,

> > > > > >> and it does make sense to just do the defaults.
> > > > > >> +1 (personally speaking) to this – will save soo much
of my 
> > > > > >> +time as I
> > > > > >> depend on this for my react-native-cordova-plugin adapter.

> > > > > >> Your changes will make life so much easier ☺
> > > > > >>
> > > > > >> How do the plugins break? Will plugins have to make change?

> > > > > >> In a way, it may make sense to do this with big changes
at 
> > > > > >> Google I/O – that way, we just have 1 breaking change,
and 
> > > > > >> plugin authors have to look at the changes just once.
> > > > > >>
> > > > > >
> > > > > >Ideally they shouldn't break, but I can't guarantee that.  I

> > > > > >do have to
> > > > > change how plugins are installed in the Android cordova 
> > > > > scripts, but the cordova-common work abstracted all that out 
> > > > > and made that
> > easier.
> > > > > A user who hasn't tweaked their app shouldn't notice the
> difference.
> > > > > >
> > > > > >That said, the users who have may notice stuff, and I have no

> > > > > >idea how
> > > > > Crosswalk would work with this yet.  It'd be good to work with 
> > > > > them once we have something more working.
> > > > > >
> > > > > >
> > > > > >>
> > > > > >> On 5/17/16, 1:55 PM, "Joe Bowser" <bowserj@gmail.com>
wrote:
> > > > > >>
> > > > > >> >Hey
> > > > > >> >
> > > > > >> >I know people have been waiting for this for a very
long 
> > > > > >> >time, but I wrote up a proposal to change the project
so 
> > > > > >> >it's an Android Studio
> > > > > project.
> > > > > >> >Given that Android Studio is on 2.1.1, I think it's
time 
> > > > > >> >we moved forward and changed things around.
> > > > > >> >
> > > > > >> >Proposal PR is here:
> > > > > >> >https://github.com/cordova/cordova-discuss/pull/45
> > > > > >> >
> > > > > >> >Branch where Proof of Concept work is being done is
here:
> > > > > >> >https://github.com/infil00p/cordova-android/tree/studio_pr
> > > > > >> >ojec
> > > > > >> >t_
> > > > > >> >st
> > > > > >> >ruc
> > > > > >> >ture
> > > > > >> >
> > > > > >> >The main roadblock to doing this, of course is migration

> > > > > >> >of plugins and custom code, as well as assets, but I
think 
> > > > > >> >Android developers would welcome this change because
we're 
> > > > > >> >acting more like a regular, normal Android project again

> > > > > >> >and not some old, weird legacy/special
> > > > > case thing.
> > > > > >> >I've already did some exploratory work with the old

> > > > > >> >cordova-android-studio version of cordova-common, and

> > > > > >> >installing plugins works fine depending on what version
of 
> > > > > >> >Cordova you're
> > > using.
> > > > > >> >
> > > > > >> >The other thing that has me stuck is all the functionality

> > > > > >> >in the gradle files.  I would love to rip out a lot
of the 
> > > > > >> >stuff we autogenerate in there, such as the 
> > > > > >> >settings.gradle file that caused me a huge headache

> > > > > >> >earlier today when I tried to get importing to work.
 It'd 
> > > > > >> >also be good to have a documented process on how we
set 
> > > > > >> >the Application ID, since I can't quite figure out how
we 
> > > > > >> >do that, and I know other people are struggling with
that 
> > > > > >> >as
> > > > well.
> > > > > >> >
> > > > > >> >This would be slated for Cordova-Android 6.0, and 
> > > > > >> >hopefully Google IO doesn't have too many surprises
that break us.
> > > > > >> >
> > > > > >> >Joe
> > > > > >>
> > > > > >>
> > > > > >
> > > > > >-------------------------------------------------------------
> > > > > >----
> > > > > >--
> > > > > >-- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > > > > >For additional commands, e-mail: dev-help@cordova.apache.org
> > > > >
> > > > >
> > > >
> > >
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > For additional commands, e-mail: dev-help@cordova.apache.org
> >
>
>
>
> --
>
> *Frederico Galvão*
>
> Diretor de Tecnologia
>
> PontoGet Inovação Web
>
>
> ( +55(62) 8131-5720
>
> * 
> https://na01.safelinks.protection.outlook.com/?url=www.pontoget.com.br&data=01%7c01%7cjasongin%40microsoft.com%7ce35038f703e94fa3c53e08d38a7466c9%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=QvcIz5Ccav40gTq%2f2yfEiOOYN%2br%2ffZe0PVtAo1ZtsM8%3d
<https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fwww.pontoget.com%2f&data=01%7c01%7cjasongin%40microsoft.com%7ce35038f703e94fa3c53e08d38a7466c9%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=NKbjT7wey%2fKPuo3JMqDAb7U2M0lSbmvJZbN9aF67VM0%3d>
>
Mime
View raw message