Question

I'm having a gradle build issue where I'm getting the error "No resource found that matches the give name ..." for a bunch of @string references in my layout files in the core module which is referencing string from the XML files in other modules.

Here's my basic layout structure (this is an old Eclipse project that I'm trying to convert to gradle in Android Studio).

Main Project Folder
-google-play-services_lib
-MainModule (this is the main module that references the other modules)
-LibraryModule
-ZXing

There's currently nothing in my build.gradle at the main project level and my main settings.gradle only includes the following items:

include ':LibraryModule'
include ':google-play-services_lib'
include ':MainModule'
include ':ZXing'

Here's the build.gradle for my main module that should run when the application is opened.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':LibraryModule')
    compile project(':ZXing')
    compile project(':google-play-services_lib')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

All of the "No resource found..." messages that I'm getting are in the MainModule and the strings they are referencing are in the LibraryModule. Any ideas on what might be going wrong in this build here?

EDIT: Adding my LibraryModule gradle.build file per request.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':ZXing')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
Was it helpful?

Solution

Your LibraryModule should use the android-library gradle plugin. You can't share res between 2 application modules.

A module is a component of your app that you can build, test, or debug independently. Modules contain the source code and resources for your app. Android Studio/Gradle projects contain three kinds of modules:

  • Java library modules contain reusable code. The build system generates a JAR package for Java library modules.
  • Android library modules contain reusable Android-specific code and resources. The build system generates an AAR (Android ARchive) package for library modules.
  • Android application modules contain application code and may depend on library modules, although many Android apps consists of only one application module. The build system generates an APK package for application modules.

http://developer.android.com/sdk/installing/studio-build.html#projectModules

Should shed more light on this issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top