2017-05-25 96 views
0

當我運行我的應用程序在我的設備[7.1上運行]應用程序運行良好,但是當我運行它在我的opo上運行在4.4它墜毀,當我嘗試將它給了應用程序無法安裝錯誤android應用程序崩潰或不安裝後使用android studio

我已經建立>生成APK簽署,並已使用了

我基本上是新的這一切,所以如果有人能幫助我了的是Android 5.0的設備上運行什麼問題是我會很高興

我的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> 

我mainactivity是

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> 
+1

什麼*錯誤日誌*顯示?發表它。 –

+0

我沒有得到任何錯誤日誌。它說apk已成功生成。 – Kishore

+0

在設備中安裝應用程序時跟蹤錯誤。 –

回答

0

您在您的應用程序級的build.gradle文件,在該文件中你有這兩個屬性:

  • minSdkVersion 16

  • targetSdkVersion 23本

//這些API級別

改變他們根據你的要求。

+0

因此,當我通過adb使用我的手機運行它們時,它會安裝,但是當我拿到apk並手動嘗試安裝它時,說應用程序無法安裝。爲什麼這 – Kishore

0

對於Hamza說的話,你必須設置你的min和target api不與kitkat兼容。對於未安裝的應用程序,即1:您的應用程序安裝了相同的軟件包名稱,2:未設置LAUNCH和DEFAULT意圖(它們看起來像),或3:它以某種方式被損壞。請在發生崩潰時發佈您的logcat。根據您的手機並下載LogCat。

+0

好吧應用程序不會崩潰我不知道什麼解決了它,併爲它的設置在最低17和目標25的API。建立應用程序時,我嘗試通過將其移動到SD卡安裝它,它失敗。但是當我通過adb運行應用程序時,它會自動安裝並運行。 – Kishore