gpt4 book ai didi

android - Android应用在旧设备上崩溃

转载 作者:行者123 更新时间:2023-12-03 05:00:01 25 4
gpt4 key购买 nike

我的应用程序可以在手机上完美运行。在某些较旧的设备上,它崩溃了:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blub.bla/com.blub.bla.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572)
...
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at
...
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_google_plus_icon.xml from drawable resource ID #0x7f0700ab
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2872)
...
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid color state list tag gradient
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:217)
at
...

我检查了其他帖子,大部分时间都与gradle有关,并且可以说我设置了 vectorDrawables.useSupportLibrary = true

Gradle文件:
apply plugin: 'com.android.application'

android {
compileSdkVersion 27


repositories {
mavenCentral()
}
defaultConfig {
applicationId "com.blub.bla"
vectorDrawables.useSupportLibrary = true
minSdkVersion 19
targetSdkVersion 27

versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

android {
lintOptions {
disable 'RestrictedApi'
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.facebook.android:facebook-login:[4,5)'
implementation 'com.facebook.android:facebook-share:[4,5)'
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'
implementation 'com.android.support:support-v4:27.0.1'

implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.4.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
implementation 'com.google.android.gms:play-services-location:10.+'
implementation 'com.google.android.gms:play-services-places:10.+'
implementation 'com.google.maps.android:android-maps-utils:0.4+'

implementation 'eu.the4thfloor.volley:com.android.volley:2015.05.28'
testImplementation 'junit:junit:4.12'
}

编辑:
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/bg"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:menu="@menu/activity_main_drawer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
<com.facebook.share.widget.ShareButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:id="@+id/fb_share_button"/>
<ImageButton
android:id="@+id/sm_twitter"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_twitter_bird_logo"
android:background="@color/transparent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
<ImageButton
android:id="@+id/sm_facebook"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_f_icon_color"
android:background="@color/transparent"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/sm_twitter"
/>
<ImageButton
android:id="@+id/sm_gplus"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_google_plus_icon"
android:background="@color/transparent"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/sm_facebook"
/>
</RelativeLayout >
</RelativeLayout>
</android.support.design.widget.NavigationView>>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@drawable/bg"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_filter"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="175dp"
android:orientation="horizontal">
<include
layout="@layout/filter_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

有谁知道该如何解决? :(

最佳答案

的第一个问题:我在drawable/v21中有一些资源,而不是drawable(不容易看到,因为它在Android Studio中显示了相同的文件夹,只是文件名旁边带有(21)
第二个问题:使用app:srcCompat代替android:backgroundandroid:res

关于android - Android应用在旧设备上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47681953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com