应用程序适用于某些手机,但不适用于其他手机

App works on some phones and not on others

我已经使用了很长一段时间的应用程序现在似乎可以在我的 phone 上运行,但是当我将它安装在其他 phone 上时,它要么正确显示,要么部分显示,或者由于某种原因根本无法打开。我检查了清单:

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">
    <activity android:name=".activities.Checkbox">
    </activity>
    <activity android:name=".activities.InputActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".activities.ReviewActivity">
    </activity>
</application>

请注意,我的 phone 上的 API 等级是 27,它有效,我试过其他 Android 8 phones,在某些上它有效,在有些它部分工作(见下图,缺少一个按钮),有些 phone 应用程序打开,空白一两秒然后关闭。

你通常应该在第一个activity:

Huawei P9 上有什么(见缺少的按钮):

在其他 phone 上,应用程序安装但不会显示第一个 activity,并且会在几秒钟内关闭而不会崩溃。

这是第一个 XML 的代码 activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_10">

<View
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:background="@color/colorPrimary" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:orientation="vertical"
    android:padding="@dimen/spacing_mlarge">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/spacing_middle"
        android:visibility="visible"
        app:cardCornerRadius="6dp"
        app:cardElevation="5dp">
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/spacing_mlarge">

            <TextView
                android:id="@+id/input_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="@dimen/spacing_xlarge"
                android:layout_marginTop="@dimen/spacing_middle"
                android:text="Bienvenue sur MBTouch!"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/green_500"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Numéro d'identification:"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_identif"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date de naissance (jj/mm/aaaa):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_naiss"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="date"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Poids (kg.g) (ex: 84.2):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_poids"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Taille (m.cm) (ex: 1.82):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_taille"
                android:layout_width="match_parent"
                android:inputType="numberDecimal"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <Button
                android:id="@+id/input_start"
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:onClick="onContinue"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:background="@drawable/btn_rounded_primary"
                android:text="Commencer"
                android:textAllCaps="false"
                android:textColor="@android:color/white"
                android:textStyle="bold" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Application conçue par S.C. iNeedHelp S.R.L."
                android:gravity="center_horizontal"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="On vous attend sur https://ineedhelp.be/ !"
                android:gravity="center_horizontal"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <ImageView
                android:layout_width="180dp"
                android:layout_height="60dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="@dimen/spacing_mlarge"
                android:layout_marginTop="@dimen/spacing_large"
                android:src="@drawable/ineedhelp"/>

        </LinearLayout>
        </ScrollView>
    </android.support.v7.widget.CardView>

    <View
        android:layout_width="0dp"
        android:layout_height="@dimen/spacing_large" />

</LinearLayout>

这里是 Java 第一个 activity:

public class InputActivity 扩展 AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_input);
}

public void onContinue(View v){
    EditText i = (EditText) findViewById(R.id.input_identif);
    EditText d = (EditText) findViewById(R.id.input_naiss);
    EditText p = (EditText) findViewById(R.id.input_poids);
    EditText t = (EditText) findViewById(R.id.input_taille);

    String ident = i.getText().toString();
    String date = d.getText().toString();
    String poids = p.getText().toString();
    String taille = t.getText().toString();

    if (ident.equals("")) {
        Toast.makeText(getApplicationContext(),"Le numéro d'identification ne peut pas être vide!",
                Toast.LENGTH_SHORT).show();
    } else {
        if (!isValidDate(date)) {
            Toast.makeText(getApplicationContext(),"Veuillez introduire une date au format JJ/MM/AAAA (ex: 12/10/1975).",
                    Toast.LENGTH_SHORT).show();
        } else {
            if(!isValidDouble(poids)){
                Toast.makeText(getApplicationContext(),"Veuillez introduire un nombre (avec un point, pas de virgule) pour le poids (ex: 75.3).",
                        Toast.LENGTH_SHORT).show();
            } else {
                if(!isValidDouble(taille)){
                    Toast.makeText(getApplicationContext(),"Veuillez introduire un nombre (avec un point, pas de virgule) pour la taille (ex: 1.85).",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Double tl = Double.parseDouble(taille.trim());
                    Double po = Double.parseDouble(poids.trim());
                    Intent mIntent = new Intent(this, Checkbox.class);
                    mIntent.putExtra("identification", ident);
                    mIntent.putExtra("date", date);
                    mIntent.putExtra("poids", po.toString());
                    mIntent.putExtra("taille", tl.toString());
                    Double bmi = (po / (tl*tl));
                    mIntent.putExtra("bmi", bmi.toString());
                    Toast.makeText(getApplicationContext(),"BMI: " + bmi.toString(),
                            Toast.LENGTH_SHORT).show();
                    startActivity(mIntent);
                }
            }

        }
    }
}

public boolean isValidDate(String dateString) {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    try {
        df.parse(dateString);
        return true;
    } catch (ParseException e) {
        return false;
    }
}

public boolean isValidDouble(String number) {
    try {
        Double.parseDouble(number.trim());
    }
    catch(NumberFormatException e){
        return false;
    }
    return true;
}

}

Gradle:

应用插件:'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "ro.ineedhelp.patientquiz"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // google support library ---------------------------------------------------------------------
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    //noinspection GradleCompatible
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    implementation 'com.android.support:appcompat-v7:25.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:support-vector-drawable:25.4.0'

    // third party dependencies -------------------------------------------------------------------
    compile 'com.balysv:material-ripple:1.0.2'                  // ripple effect
    compile 'com.github.bumptech.glide:glide:3.7.0'             // image loader
    compile 'com.wdullaer:materialdatetimepicker:3.2.0'         // date & time picker
    compile 'com.mikhaellopez:circularimageview:3.0.2'          // circle image view
    compile 'com.github.pchmn:MaterialChipsInput:1.0.8'         // material chip
    compile 'com.hootsuite.android:nachos:1.1.1'                // material chips

    testCompile 'com.android.support:appcompat-v7:25.4.0'
}

您认为您知道是什么原因造成的吗?我使用 Level1 和 Level2 签名对 APK 进行签名。

提前致谢。

检查您的 gradle 文件或项目结构。 可能是您的 API 版本高于您的目标设备。 select 降低 API 会解决这个问题

检查应用无法运行的手机的 sdk 版本。您的应用的最低 sdk 版本是 21,手机 运行 低于 21 的 sdk 版本将不支持该应用。

好的,所以我弄清楚出了什么问题,显然有些手机不喜欢按钮上的 android:background 选项,我已经删除了它,现在它似乎可以正常工作了。

您的按钮在某些手机上丢失,因为对于某些手机来说无法找到 android:background="@drawable/btn_rounded_primary" 所以您的按钮并没有丢失,它只是不可见。要检查这一点,您应该更改按钮的 android:textColor。然后检查您的可绘制资源 "@drawable/btn_rounded_primary" 是否位于正确的目录中。 我需要更多信息来了解为什么您的应用程序在某些手机上崩溃。你能给我写下这些手机的 API 等级吗?