首页 > 解决方案 > 无法从 ...\src\main\AndroidManifest.xml 读取 packageName

问题描述

当我尝试构建我的项目时,我在 Android Studio 中收到此错误:无法从 .. 读取 packageName\src\main\AndroidManifest.xml

我之前将我的项目从 Eclipse 迁移到 Android Studio 并且 AndroidManifest.xml 文件不在上面的目录中,它位于:..\app\src\main\AndroidManifest.xml

当我创建 ..\src\main目录并将AndroidManifest.xml文件复制到其中时,我得到一个新错误列表,见下​​文。我是否必须创建该目录,或者这是导致新错误的原因?:

..\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:46: error: resource style/MyTheme (aka style/MyTheme) not found.
..\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:57: error: resource string/app_name (aka string/app_name) not found.
..\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:68: error: resource string/app_name (aka string/app_name) not found.

我已经阅读了与此类似的先前问题的答案,主要指向格式不佳的 xml 的问题,或者 build.gradle 中的 applicationId 与 AndroidManifest.xml 中的包不匹配,但不幸的是它们不适用于这种情况.

有没有人遇到过这个?

标签: androidandroid-studio

解决方案


从您的代码中,我发现可能在您的样式资源 appTheme 中未定义。所以首先将此代码放入您的 style.xml 文件中。

<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

注意:您还需要在资源文件中定义颜色。

然后将此代码添加到您的资源文件中

<string name="app_name">your app name</string>

也许它会帮助你。


推荐阅读