簡體   English   中英

使用android studio構建后,android應用程序崩潰或未安裝

[英]the android app crashes or not installs after building using android studio

當我在我的設備中運行我的應用程序時[在7.1上運行],該應用程序運行良好,但是當我在運行於4.4的opo上運行它時,它崩潰了;當我嘗試在android 5.0設備上運行它時,它給應用程序安裝了錯誤

我已經建立>生成簽名的apk並使用了

我基本上對這一切都是新手,所以如果有人可以幫助我解決問題,我會很高興

我的activity_main代碼是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bingobean.pitchblack.MainActivity"
android:weightSum="1">


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="center"
    android:src="@drawable/android"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true" />


<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="55dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="34dp"
    android:text="Pitch black"
    android:textColor="#ffffff"
    android:textSize="50sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="118dp"
    android:layout_height="109dp"
    android:layout_marginTop="144dp"
    android:text="Hit it!"
    android:textSize="24sp"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />


</RelativeLayout>

我的主要活動是

package com.bingobean.pitchblack;

import android.app.WallpaperManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

Button btn;
ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button) findViewById(R.id.button);
    img = (ImageView) findViewById(R.id.imageView1);

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WallpaperManager wallmgr = 
WallpaperManager.getInstance(getApplicationContext());
            try {
                wallmgr.setResource(+ R.drawable.android);
            } catch (IOException e){
                e.printStackTrace();
            }
            Toast.makeText(getApplicationContext(), "Wallpaper is set", 
Toast.LENGTH_SHORT).show();

        }
    });

}
}

我的Androidmanifest是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bingobean.pitchblack">

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

檢查中的應用程序級別build.gradle文件,在該文件中,您具有以下兩個屬性:

  • minSdkVersion 16

  • targetSdkVersion 23此

//這些是api級別

根據您的要求更改它們。

與Hamza所說的一樣,您必須將min和target api設置為與kitkat不兼容。 至於未安裝的應用程序,則可能是:1:您安裝了具有相同程序包名稱的應用程序; 2:未設置LAUNCH和DEFAULT意圖(看起來很正確); 3:某種程度上它已損壞。 請發布您的logcat崩潰的信息。 根您的手機並下載LogCat。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM