简体   繁体   中英

Android Studio: Gradle Build Problems/“R can't be resolved”

i just started a little project in android studio debugging and everything was fine, but then about a hour ago, i got an error, that "R" can not be resolved, so i can't reference to my layouts anymore. I searched for help on the web and here on Stackoverflow, but no solution seemed to work for me. I tried Cleaning my Project but then i got this error during gradle building:

Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Admin\AppData\Local\Android\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1

Does anyone know a solution to this? This never happened to me before and there's no need of linking me to an existing thread, because i've read all threads related to this topic on here and noone was able to help me. Thanks in advance

build gradle console: Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Admin\AppData\Local\Android\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.51 secs

R can't be resolved in Android studio happened some reasons:

  1. When face any code problem in .xml file
  2. Any theme chosen/build problem in android manifest file

Solutions:

  1. Look, if you don't write any code in xml file then just click rebuild or make project button or clean button . Your problem may be solved.
  2. If you modify your xxxxx.xml layout file then look these files and I'm sure you've written some wrong code. Like theme name problem, any referencing problem of strings, dimens, colors and so on. Correct them and may be your R can't be resolved text will be solved. Obviously, after doing this click make project button and provably get no error..

My same problem of 2 is just given below: My styles.xml file was:

<style name="MyCustomToolbar" parent="ThemeOverlay.AppCompat.Light">
    <item name="colorPrimary">#5974AB</item>
</style>

And in xml file I've written that

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
....
android:popupTheme="@style/MyCustomToolber"
>

</android.support.v7.widget.Toolbar>

Look in xml

android:popupTheme="@style/MyCustomToolber"

I've typed wrong style name and so I got that error R can't be resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM