在android studio中运行项目时遇到一个奇怪的问题,项目中包含多个模块并成功启动,但是在启动屏幕之后启动第一个活动时,Logcat指出了以下错误这条线
setContentView(R.layout.activity_layout);
错误
java.lang.NoSuchFieldError: No field TextAppearance_fontFamily of type I in class Landroid/support/v7/appcompat/R$styleable; or its superclasses (declaration of 'android.support.v7.appcompat.R$styleable' appears in /data/app/PROJECT_PACKAGE_NAME-2/base.apk)
关于这个问题的搜索很多,但没有令人信服的东西,大多数时候,人们都说“您在库和模块中都有相同的布局,或者具有重复的资源ID的多个XML布局”。我已重命名指向错误的XML文件,但无法通过它。感谢您的帮助。
XML文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/intro_bg">
<View
android:id="@+id/top_view"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:layout_marginTop="55dp"
android:alpha="0.8"
android:background="@drawable/round_corner_mobile_top" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomView"
android:layout_below="@+id/top_view"
android:paddingLeft="64dp"
android:paddingRight="64dp" />
<View
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_above="@+id/bottomView"
android:layout_below="@+id/top_view"
android:layout_marginLeft="55dp"
android:alpha="0.8"
android:background="@color/mobile_screen" />
<View
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_above="@+id/bottomView"
android:layout_alignParentRight="true"
android:layout_below="@+id/top_view"
android:layout_marginRight="55dp"
android:alpha="0.8"
android:background="@color/mobile_screen" />
<LinearLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="110dp"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp">
<View
android:id="@+id/circle1"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/circle_fill" />
<View
android:id="@+id/circle2"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/circle" />
<View
android:id="@+id/circle3"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/circle" />
<View
android:id="@+id/circle4"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/circle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/outline_button_yellow"
android:padding="4dp">
<Button
android:id="@+id/button_sign_up"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_button_yellow"
android:text="@string/signup"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/outline_button_blue"
android:padding="4dp">
<Button
android:id="@+id/button_sign_in"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_button_blue"
android:text="@string/login"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/outline_button_gray"
android:padding="4dp">
<Button
android:id="@+id/button_skip"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_button_gray"
android:text="@string/skip"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="autoCompleteTextViewStyle">@style/cursorColor</item>
<item name="android:typeface">serif</item>
</style>
<style name="YellowCheck">
<item name="colorControlNormal">@color/yellow</item> <!-- normal border color change as you wish -->
<item name="colorControlActivated">@color/yellow</item>
</style>
<style name="cursorColor" parent="Widget.AppCompat.AutoCompleteTextView">
<item name="android:textCursorDrawable">@drawable/cursor</item>
</style>
</resources>
答案 0 :(得分:2)
您需要更新我的SDK工具和SDK平台工具,选择27作为构建目标。
答案 1 :(得分:0)
首先,您需要检查具有所有依赖项的应用程序级别build.gradle以及编译sdk和目标sdk。
完成此操作后,只需从Build-> Clean build进行一个干净的构建,项目就应该构建而没有任何错误。