Android Studio / Gradle not including assets directory by default

7,236 views
Skip to first unread message

Daniele Segato

unread,
Sep 26, 2013, 12:53:30 PM9/26/13
to adt...@googlegroups.com
Hi,

I created a project with Android Studio

so the directory structure is as follow:

src/
    main/
           java/
           res/

Today I was trying to integrate the TagManager for the first time.
I followed the guide indicated to place a file in res/assets/tagmanager/GTM-XXXXXX.json for the default configuration.

I did.

And it simply printed this in the log when trying to open the container:
09-26 18:39:28.203    1379-1379/com.my.package.debug W/GoogleTagManager﹕ No asset file: tagmanager/GTM-XXXXXX found.
09-26 18:39:28.203    1379-1379/com.my.package.debug W/GoogleTagManager﹕ No asset file: tagmanager/GTM-XXXXXX.json found (or errors reading it).
09-26 18:39:28.203    1379-1379/com.my.package.debug W/GoogleTagManager﹕ No default container found; creating an empty container.

Now I struggled a very long time trying to figure out what was wrong with that but the json was valid.

In the end I checked if the file was actually there using the AssetManager... it wasn't.

So I manually added this to the gradle configuration:

    sourceSets {
        main {
            assets.srcDirs = ['src/main/res/assets']
        }
    }

With this it included the assets directory and finally my json was loaded.

But wait.
It's not done yet....

It works when I execute it from command line.
I couldn't find any way to make it work from inside Android Studio.

Android Studio simply insisted to ignore the assets directory.


My build.gradle is this:
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    final RELEASE_PROVIDER = "com.my.package.sync.provider";
    final RELEASE_ACCOUNT_TYPE = "myaccount.com";
    final DEBUG_PROVIDER = "com.my.package.sync.debug.provider";
    final DEBUG_ACCOUNT_TYPE = "devel.myaccount.com";
    final RELEASE_ACCOUNT_NAME_DUMMY = "dummyaccount";
    final DEBUG_ACCOUNT_NAME_DUMMY = "dummyaccountdebug";

    final BUILD_CONFIG_CORMAT = "public static final String PROVIDER_AUTHORITY = \"%s\";\n" +
                            "    public static final String ACCOUNT_TYPE = \"%s\";\n" +
                            "    public static final String ACCOUNT_NAME_DUMMY = \"%s\";";

    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 18
    }

    sourceSets {
        main {
            assets.srcDirs = ['src/main/res/assets']
        }
    }

    buildTypes {
        release {
//            runProguard true
            buildConfig String.format(BUILD_CONFIG_CORMAT, RELEASE_PROVIDER, RELEASE_ACCOUNT_TYPE, RELEASE_ACCOUNT_NAME_DUMMY);
        }
        debug {
//            jniDebugBuild true
//            runProguard true
            packageNameSuffix ".debug"
            versionNameSuffix "-debug"
            buildConfig String.format(BUILD_CONFIG_CORMAT, DEBUG_PROVIDER, DEBUG_ACCOUNT_TYPE, DEBUG_ACCOUNT_NAME_DUMMY);
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile project(':ViewPagerIndicator:library')
    compile project(':volley')
    compile files('libs/libGoogleAnalyticsServices_3.0.jar')

}

The debug/release settings only contains an AndroidManifest with the 3 settings for the SyncAdapter in my app, linking to different xml/ files.

It didn't matter how many times I clicked the icon to sync with gradle or closed/reopened the project. I had to DELETE it from the list of project in Android Studio and re-import it to make it work again.

Have I done something weird?
Am I the only one experiencing this issue?
Shouldn't the assets directory be included by default without me specifying it?

Thanks in advance,
Regards,
Daniele

Marcus Ramsden

unread,
Sep 26, 2013, 12:58:20 PM9/26/13
to adt...@googlegroups.com, Daniele Segato
The assets directory should be under src/main as opposed to src/main/res for Android Studio to pick it up. That's also the expected location for the directory with Gradle.

-- 
Marcus Ramsden
marcus....@smilemachine.com | 07890 397330 (mobile)

Smile Machine, 6-8 Bonhill Street, 3rd Floor, London, EC2A 4BX
www.smilemachine.com | @SmileMcn | Facebook | 0207 060 5100

Smile Machine Limited, registered in England and Wales, Company No. 07242537. Registered Office: Kemp House, 152 City Road, London, EC1V 2NX
--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Daniele Segato

unread,
Sep 27, 2013, 8:10:05 AM9/27/13
to adt...@googlegroups.com, Daniele Segato
Uh?

I didn't noticed
you are right:

And why is that?

It was within res/ folder in Eclipse I remember

Thanks... I'll pay more attention to the doc next time
And I move it back to where it is supposed to be
Reply all
Reply to author
Forward
0 new messages