【问题标题】:the android app crashes or not installs after building using android studio使用 android studio 构建后,android 应用程序崩溃或未安装
【发布时间】:2017-05-25 11:48:39
【问题描述】:

当我在我的设备上运行我的应用程序 [在 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();

        }
    });

}
}

我的 Android 清单是

<?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>

【问题讨论】:

  • 显示什么错误日志?发布它。
  • 我没有收到任何错误日志。它说 apk 生成成功。
  • 在设备中安装应用程序时跟踪错误。

标签: java android android-layout android-studio sdk


【解决方案1】:

检查您的应用程序级别的 build.gradle 文件,在该文件中您有这两个属性:

  • minSdkVersion 16

  • targetSdkVersion 23 这个

// 这些是 api 级别

根据您的要求更改它们。

【讨论】:

  • 因此,当我使用手机通过 adb 运行它们时,它会安装,但是当我使用 apk 并手动尝试安装时,它说应用程序无法安装。为什么会这样
【解决方案2】:

Hamza 所说的同上,您必须将 min 和 target api 设置为与 kitkat 不兼容。至于未安装的应用程序,即 1:您安装了具有相同软件包名称的应用程序,2:未设置 LAUNCH 和 DEFAULT 意图(它们似乎是),或 3:它以某种方式损坏了。请发布您的 logcat 以了解它何时崩溃。 Root 手机并下载 LogCat。

【讨论】:

  • 好吧,应用程序不会崩溃,我不确定是什么解决了它,对于 api,它的设置为 min 17 和 target 25。构建应用程序后,当我尝试通过将其移动到 sd 卡来安装它时, 它失败。但是当我通过 adb 运行应用程序时,它会自动安装并运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
相关资源
最近更新 更多