Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle assemble of an Android project failed, can't find R.txt

Tags:

android

gradle

Sorry for my poor English. I'm trying to migrate my project to Gradle with Android Studio, but currently the build fails during processDebugResources.

error info:

Execution failed for task ':app:processAdultDebugResources'. java.io.FileNotFoundException: C:\Projects\YYM\app\build\symbols\adult\debug\R.txt (系统找不到指定的文件。)(That Chinese means "System cannot find the file")

In addition, I found that in the build path of my project there was a R.java file under a strange path: build/source/r/debug/--output-text-symbols.

Here is a part of my build.gradle:

apply plugin: 'android'
android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 78
        versionName "1.7.72"
        ndk {
            abiFilters "armeabi"
        }
    }
    productFlavors {
        weightloss {
            packageName "com.yesudoo.yymweightloss"
        }
        adult {
            packageName "com.yesudoo.yymadult"
        }
    }
    buildTypes {
        debug {
            packageNameSuffix ".dev"
            versionNameSuffix "-dev"
        }
    }
    lintOptions {
        abortOnError false
    }
}

I'm new in Gradle, and thanks in advance for any pointers on how to solve this problem.

like image 985
rengwuxian Avatar asked Feb 11 '14 04:02

rengwuxian


2 Answers

I had the same problem, beginning when I fumbled around adding a second sub-subfolder to my assets directory. Removing the folder (basically undoing what I did to cause the problem) didn't help, which indicated it may be a problem with caches. The accepted answer may work, if by changing the manifest file you trigger Android Studio to invalidate its caches (apparently this is more than clean and rebuild, as I tried that several times).

Simple thing to try: go to File->Invalidate Caches and Restart.

like image 107
alr3000 Avatar answered Sep 28 '22 04:09

alr3000


So the way I fixed this was:

inside my androidTest folder, I had a java folder with my test files. But gradle requires you to have some resources inside test so that it generates the R.txt file. So what I did was created a res folder inside androidTest and added a values/strings.xml folder with one string resource.

This allowed my tests to build and run!

like image 24
Prem Avatar answered Sep 28 '22 03:09

Prem