avianey / androidsvgdrawable-plugin

Gradle plugin that generates qualified, density specific PNG drawables from SVG files at build time for your Android projects.
Apache License 2.0
262 stars 29 forks source link

outputting to build, is clobbered when clean is used.. (gradle) #24

Closed mwinters-stuff closed 2 years ago

mwinters-stuff commented 9 years ago

Configured

android{
  sourceSets{
        main.res.srcDirs = [main.res.srcDirs,"build/generated/res/main"]
    }
}

// create a task to convert SVG to PNG
task svgToPng(type: SvgDrawableTask) {
    from = file('src/main/svg-png')
    // specify the android res folder
    to = file('build/generated/res/main')
    // create qualified directories if missing
    createMissingDirectories = true
    // override files only if necessary
    overrideMode = 'ifModified'
    // the /res/drawable directory will contains mdpi resources
//  fallbackDensity = 'mdpi'
    // let generate PNG for the following densities only
    targetedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']
    // relative path of the file specifying nine patch specs
    ninePatchConfig = file('src/main/svg-png/9patch.json')
    // output format of the generated resources
    outputFormat = 'PNG'
    to.mkdirs()
}

When a release build is done (i do this in jenkins ci) I add clean as the first task, the png files are generated under the correct directory, then at some stage further down the build the directories are cleared, then the build fails as it cant find the drawables.

I couldn't find the task that was doing this, removing the "clean" stopped the files from being cleared.

avianey commented 9 years ago

Currently, the generateDrawable task is bound to the android:preBuild one... It might be executed before the clean one which will be a problem. Can you output the task execution order of your gradle build please ?

mwinters-stuff commented 9 years ago
:WidgetsApps:clean
:wizardpager:clean
:WidgetsApps:svgToPng
:WidgetsApps:svgToPngNzphoneaccount
:WidgetsApps:svgToPngWalletmerchant
:WidgetsApps:preBuild
:WidgetsApps:preNzphoneaccountReleaseBuild
:WidgetsApps:compileNzphoneaccountReleaseNdk UP-TO-DATE
:WidgetsApps:checkNzphoneaccountReleaseManifest
:WidgetsApps:preNzphoneaccountDebugBuild
:WidgetsApps:preWalletmerchantDebugBuild
:WidgetsApps:preWalletmerchantReleaseBuild
:wizardpager:compileLint
:wizardpager:copyReleaseLint UP-TO-DATE
:wizardpager:preBuild UP-TO-DATE
:wizardpager:preReleaseBuild UP-TO-DATE
:wizardpager:checkReleaseManifest
:wizardpager:preDebugAndroidTestBuild UP-TO-DATE
:wizardpager:preDebugBuild UP-TO-DATE
:wizardpager:prepareComAndroidSupportAppcompatV72200Library
:wizardpager:prepareComAndroidSupportSupportV42200Library
:wizardpager:prepareComGoogleAndroidGmsPlayServices700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesAds700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesAnalytics700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesAppindexing700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesAppstate700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesBase700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesCast700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesDrive700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesFitness700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesGames700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesGcm700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesIdentity700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesLocation700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesMaps700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesNearby700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesPanorama700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesPlus700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesSafetynet700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesWallet700Library
:wizardpager:prepareComGoogleAndroidGmsPlayServicesWearable700Library
:wizardpager:prepareReleaseDependencies
:wizardpager:compileReleaseAidl
:wizardpager:compileReleaseRenderscript
:wizardpager:generateReleaseBuildConfig
:wizardpager:generateReleaseAssets UP-TO-DATE
:wizardpager:mergeReleaseAssets
:wizardpager:generateReleaseResValues UP-TO-DATE
:wizardpager:generateReleaseResources
:wizardpager:mergeReleaseResources
:wizardpager:processReleaseManifest
:wizardpager:processReleaseResources
:wizardpager:generateReleaseSources
:wizardpager:compileReleaseJava
:wizardpager:extractReleaseAnnotations
:wizardpager:mergeReleaseProguardFiles UP-TO-DATE
:wizardpager:processReleaseJavaRes UP-TO-DATE
:wizardpager:packageReleaseJar
:wizardpager:compileReleaseNdk UP-TO-DATE
:wizardpager:packageReleaseJniLibs UP-TO-DATE
:wizardpager:packageReleaseLocalJar UP-TO-DATE
:wizardpager:packageReleaseRenderscript UP-TO-DATE
:wizardpager:packageReleaseResources
:wizardpager:bundleRelease
:WidgetsApps:prepareComAndroidSupportAppcompatV72200Library
:WidgetsApps:prepareComAndroidSupportCardviewV72200Library
:WidgetsApps:prepareComAndroidSupportGridlayoutV72200Library
:WidgetsApps:prepareComAndroidSupportRecyclerviewV72200Library
:WidgetsApps:prepareComAndroidSupportSupportV42200Library
:WidgetsApps:prepareComBignerdranchAndroidRecyclerviewMultiselect01Library
:WidgetsApps:prepareComEowiseRecyclerviewStickyheaders052Library
:WidgetsApps:prepareComGithubRampoUpdatecheckerLibrary215Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServices700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesAds700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesAnalytics700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesAppindexing700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesAppstate700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesBase700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesCast700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesDrive700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesFitness700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesGames700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesGcm700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesIdentity700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesLocation700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesMaps700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesNearby700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesPanorama700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesPlus700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesSafetynet700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesWallet700Library
:WidgetsApps:prepareComGoogleAndroidGmsPlayServicesWearable700Library
:WidgetsApps:prepareComJpardogoMaterialtabstripLibrary109Library
:WidgetsApps:prepareComMalinskiySuperrecyclerview110Library
:WidgetsApps:prepareComMelnykovFloatingactionbutton130Library
:WidgetsApps:prepareComMikepenzAboutlibrariesLibrary459Library
:WidgetsApps:prepareComOguzdevCircularFloatingActionMenu102Library
:WidgetsApps:prepareComRaizlabsAndroidDBFlow180Library
:WidgetsApps:prepareNZPhoneAccountWidgetBetaWizardpagerUnspecifiedLibrary
:WidgetsApps:prepareNzOrgWintersAndroidBetterpickers220Library
:WidgetsApps:prepareNzOrgWintersAndroidLineChart220Library
:WidgetsApps:prepareNzOrgWintersAndroidSupportV4Preferencefragment220Library
:WidgetsApps:prepareNzOrgWintersColourSelector220Library
:WidgetsApps:prepareNzOrgWintersCustomPreferences220Library
:WidgetsApps:prepareNzOrgWintersUnlockChecker220Library
:WidgetsApps:prepareOrgSolovyevAndroidCheckout072Library
:WidgetsApps:prepareSeEmilsjolanderStickylistheaders250Library
:WidgetsApps:prepareNzphoneaccountReleaseDependencies
:WidgetsApps:compileNzphoneaccountReleaseAidl
:WidgetsApps:compileNzphoneaccountReleaseRenderscript
:WidgetsApps:generateNzphoneaccountReleaseBuildConfig
:WidgetsApps:generateNzphoneaccountReleaseAssets UP-TO-DATE
:WidgetsApps:mergeNzphoneaccountReleaseAssets
:WidgetsApps:generateNzphoneaccountReleaseResValues UP-TO-DATE
:WidgetsApps:generateNzphoneaccountReleaseResources
:WidgetsApps:mergeNzphoneaccountReleaseResources
:WidgetsApps:processNzphoneaccountReleaseManifest
:WidgetsApps:processNzphoneaccountReleaseResources Position 107:20-44 : No resource found that matches the given name (at 'image' with value '@drawable/ic_action_cart').
 Position 115:20-48 : No resource found that matches the given name (at 'image' with value '@drawable/ic_action_settings').
 Position 123:20-45 : No resource found that matches the given name (at 'image' with value '@drawable/ic_action_about').
 Position 74:20-54 : No resource found that matches the given name (at 'src' with value '@drawable/ic_action_chart_settings').
 Position 17:33-60 : No resource found that matches the given name (at 'background' with value '@drawable/heading_underline').
 Position 100:26-53 : No resource found that matches the given name (at 'src' with value '@drawable/ic_action_refresh').
 Position 6:21-48 : No resource found that matches the given name (at 'icon' with value '@drawable/ic_action_refresh').
 Position 12:21-50 : No resource found that matches the given name (at 'icon' with value '@drawable/ic_action_notify_on').

 FAILED

This project has 2 flavours and a library dependency, builds nicely until I changed to put the generated drawables in the build directory ..

Looking at this, I would think that the 'generateReleaseResources' and its respective targets and flavours would be a good spot to hook into.. leaves it later in the build.. Its possible the clean is being done after the dependant library thats built first.

avianey commented 9 years ago

"This project has 2 flavours and a library dependency"

Do you mean that the svgDrawableTask is executed for the library only ? Could you give me more informations about the file structure of your project ?

mwinters-stuff commented 9 years ago

Ok..

Its like

RootFolder\
  build.gradle
  Library1\
    build.gradle
    build\
    src\

  AppProject\
    build.gradle
    build\
      generated\res\
        main\
        appflavour1\
        appflavour2\
    src\
      main\
        assets\
        java\
        res\
        svg-png\
      appflavour1\
        assets\
        java\
        res\
        svg-png\
      appflavour2\
        assets\
        java\
        res\
        svg-png\
      testAppFlavour1\
      testAppFlavour2\
      test\

The svgtoPng is run on the app main/ appflavour1 and appflavour2, (for each
build), the library has its own drawable resources..

Its an interesting one. I had to remove the clean task from before the
assembleRelease task to get the apps to build.
:)