android - Override Java version when building a Cordova project with gradle -
i trying build cordova project using gradle build tool. in cordova project have own plugin requires java 1.7.
in build.gradle comes cordova java version 1.6. build.gradle:
android { compileoptions { sourcecompatibility javaversion.version_1_6 targetcompatibility javaversion.version_1_6 } }
the build.gradle comes great big warning says generated file should not edited, way customize gradle build step - understand - create build-extras.gradle file.
i have created build-extras.gradle file , tried following:
android { compileoptions { sourcecompatibility javaversion.version_1_7 targetcompatibility javaversion.version_1_7 } }
but not seem work. still error when build project.
error:
> strings in switch not supported in -source 1.6 > switch (action) { > ^ (use -source 7 or higher enable strings in switch)
can please me figure out how setup gradle make work?
i've been trying solve same problem, , came here hoping find answer! anyway, although there no answer, mention of build-extras.gradle
put me on right track, , following works me...so thanks.
to begin thought might try using same syntax you, try work out wrong. far can tell fails because build-extras.gradle
file not magically merged build.gradle
, instead loaded , executed using gradle apply from
approach. , since happens before android
closure in process, , android
values override our 'extra' values.
(i don't have time delve more need gradle or groovy, apologies if terminology not precise...)
however, work if used postbuildextras()
method.
if @ bottom of build.gradle
file generated cordova you'll see if such method (i.e., postbuildextras
) exists on ext
, gets called. since last thing in configuration script guess point of method can use override anything.
i therefore ended build-extras.gradle
:
ext.postbuildextras = { android { compileoptions { sourcecompatibility javaversion.version_1_7 targetcompatibility javaversion.version_1_7 } } }
i had working quite in investigations kept trying other approaches since suspect technique fail when try have multiple build-extras.gradle
files -- which, given we're both talking cordova plugins, likely.
there technique looks promising plugins, use <framework>
element in plugin.xml
, approach never plugin-specific module load/import/whatever. i'll take @ when plugin #2, technique described above gets me big leap further on morning, again build-extras.gradle
clue. ;)
Comments
Post a Comment