2017-05-25 95 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