无法在Android Studio中解析符号“R”:“清单合并失败并出现多个错误,请参阅日志”

时间:2022-05-09 15:39:21

I'm a beginner and I use Android Studio. A problem keeps on bothers me.

我是初学者,我使用的是Android Studio。一个问题一直困扰着我。

It keeps on showing "Cannot Resolve symbol 'R' " everywhere with R.XXX.XXX

它继续使用R.XXX.XXX显示“无法解析符号'R'”

I've tried:

我试过了:

1.checking my xml files, including manifest

1.检查我的xml文件,包括清单

2.checking SDK whether Build Tools is installed

2.检查SDK是否安装了Build Tools

3.clean project

3.清洁项目

4.rebuild project

4.rebuild项目

5.sync project with Gradle files

5.sync项目与Gradle文件

6.every way I could find on Internet

我可以在互联网上找到的任何方式

while rebuilding project the message shows "manifest merger failed with multiple errors, see logs"

重建项目时,消息显示“清单合并失败并出现多个错误,请参阅日志”

I briefly paste a part of my activity here:

我在这里简要地粘贴了一部分活动:

public class Clock_mainpage extends Activity {

private Button button_start;

private static final int START_LOCATION = 1;

private Item item;


private void findButton()
 {

    button_start = (Button) findViewById(R.id.start);

 }

 private Button.OnClickListener startclock = new Button.OnClickListener() 
 {
    @Override
   public void onClick(View view) 
    {
                Intent intentMap = new Intent(Clock_mainpage.this, MapsActivity.class);

                intentMap.putExtra("lat", item.getLatitude());
                intentMap.putExtra("lng",item.getLongitude());
                intentMap.putExtra("title",item.getTitle());
                intentMap.putExtra("datetime",item.getLocaleDatetime());

                startActivityForResult(intentMap, START_LOCATION);
                finish();

        }
    };

Seems it appears to be something wrong in my Manifest.xml I post it below:

似乎我的Manifest.xml中出现了错误,我在下面发布它:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hackntu.android.clock"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission      android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" />
<activity
    android:name=".Clock_mainpage"
    android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Google Service edition -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

    <!-- Google Map API key -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <!-- Map component -->
    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps" />

        <activity/>

    <application/>

</manifest>

Well, this problem seems to be simple to every of you. But I wasted 3hours or more on it. Appreciate to all of you. Sincerely

嗯,这个问题对你们每个人来说都很简单。但我浪费了3小时或更多时间。感谢所有人。诚挚

4 个解决方案

#1


0  

You didn't past the most important think in such problem with R a imports. Problem is known and simple. For sure you had problem with some resources. R class was not generated. You get info from IDE that R can not be found and IDE propose you quick fix: import R class.

你没有通过R a进口这个问题中最重要的想法。问题是众所周知的。肯定你有一些资源的问题。没有生成R类。您从IDE获取无法找到R的信息,IDE建议您快速修复:导入R类。

But because your R was not generated at that point and IDE has only android.R avaliable. IDE impot android.R

但是因为你的R在那时没有生成,IDE只有android.R avaliable。 IDE impot android.R

Please double check imports. In import you should have:

请仔细检查进口。在导入中你应该:

yourpackage.R

#2


2  

In my case i have declared the same activity twice in the AndroidManifest.xml. So it was giving me the duplicate merger error. Once i removed that my issue was resolved. Make sure your activity is not listed twice in manifest.

在我的例子中,我在AndroidManifest.xml中声明了两次相同的活动。所以它给了我重复的合并错误。一旦我删除,我的问题就解决了。确保您的活动未在清单中列出两次。

#3


1  

In my case the drawable ic_launcher was also being used by a dependency library. Looking at the gradle console in Android Studio helps in such situations.

在我的例子中,drawable ic_launcher也被依赖库使用。在Android Studio中查看gradle控制台有助于在这种情况下。

Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml

This solved my problem, your issue might be different but gradle console will certainly help.

这解决了我的问题,你的问题可能会有所不同,但gradle控制台肯定会有所帮助。

#4


0  

Sometimes this issues occurs because of manifest file. Delete newly added comments, empty tags like <intent-filter> </intent-filter> and rebuild your project. It should work.

有时由于清单文件而出现此问题。删除新添加的注释,空标记,如 ,然后重建项目。它应该工作。

#1


0  

You didn't past the most important think in such problem with R a imports. Problem is known and simple. For sure you had problem with some resources. R class was not generated. You get info from IDE that R can not be found and IDE propose you quick fix: import R class.

你没有通过R a进口这个问题中最重要的想法。问题是众所周知的。肯定你有一些资源的问题。没有生成R类。您从IDE获取无法找到R的信息,IDE建议您快速修复:导入R类。

But because your R was not generated at that point and IDE has only android.R avaliable. IDE impot android.R

但是因为你的R在那时没有生成,IDE只有android.R avaliable。 IDE impot android.R

Please double check imports. In import you should have:

请仔细检查进口。在导入中你应该:

yourpackage.R

#2


2  

In my case i have declared the same activity twice in the AndroidManifest.xml. So it was giving me the duplicate merger error. Once i removed that my issue was resolved. Make sure your activity is not listed twice in manifest.

在我的例子中,我在AndroidManifest.xml中声明了两次相同的活动。所以它给了我重复的合并错误。一旦我删除,我的问题就解决了。确保您的活动未在清单中列出两次。

#3


1  

In my case the drawable ic_launcher was also being used by a dependency library. Looking at the gradle console in Android Studio helps in such situations.

在我的例子中,drawable ic_launcher也被依赖库使用。在Android Studio中查看gradle控制台有助于在这种情况下。

Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml

This solved my problem, your issue might be different but gradle console will certainly help.

这解决了我的问题,你的问题可能会有所不同,但gradle控制台肯定会有所帮助。

#4


0  

Sometimes this issues occurs because of manifest file. Delete newly added comments, empty tags like <intent-filter> </intent-filter> and rebuild your project. It should work.

有时由于清单文件而出现此问题。删除新添加的注释,空标记,如 ,然后重建项目。它应该工作。