简体   繁体   English

应用程序在调试期间在手机上工作,在安装apk时不起作用

[英]App works on phone during debugging, does not work when apk is installed

I have made an app that uses GPS, Internet, FusedAPI and KSOAP. 我制作了一款使用GPS,互联网,FusedAPI和KSOAP的应用程序。 When I debug the app on my mobile using android studio, the app works fine. 当我使用android studio在我的手机上调试应用程序时,该应用程序工作正常。 However when I create apk (signed), the activity that deals with Google Map, Fused API and GPS, does not work. 但是,当我创建apk(已签名)时,处理Google Map,Fused API和GPS的活动不起作用。 All I can see is the screen flickering and the app returns to the activity before it. 我只能看到屏幕闪烁,应用程序返回到之前的活动。

Can anyone tell me what could possible be wrong. 谁能告诉我什么可能是错的。

build.gradle (Module) build.gradle(模块)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    dexOptions {
        javaMaxHeapSize "4g"
    }

    defaultConfig {
        multiDexEnabled true
        applicationId "online.hannuveda.transafe_rx"
        minSdkVersion 11
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'

    compile files('libs/ksoap2-android-assembly-2.4-jar-with-dependencies .jar')
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.maps.android:android-maps-utils:0.3+'
    compile 'com.github.aakira:expandable-layout:1.6.0@aar'
}

build.gradle (Project) build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Since you are using the google-play-services dependency ( 'com.google.android.gms:play-services:9.4.0' ), you should declare your application of type MultidexApplication. 由于您使用的是google-play-services依赖项( 'com.google.android.gms:play-services:9.4.0' ),因此您应该声明您的应用程序类型为MultidexApplication。

At the moment, you have just added multiDexEnabled true to the app level build.gradle file, which is not enough for a multidex configuration. 目前,您刚刚将multiDexEnabled true添加到应用程序级build.gradle文件中,这对于multidex配置来说还不够。 You should also make changes in your Manifest and dependencies as well. 您还应该对Manifest和依赖项进行更改。 Anyway, the instructions are the following : 无论如何,说明如下:

1- Add the multidex dependency to your app level build.gradle : 1-将multidex依赖项添加到应用程序级别build.gradle

 compile 'com.android.support:multidex:1.0.1'

2- Enable the multidex in your defaultConfigs in the app level build.gradle : 2-在app level build.gradle中的defaultConfigs中启用multidex:

android {

defaultConfig {
    ...

    // Enabling multidex support.
    multiDexEnabled true
   }
...
}

3- Define a new class MyApplication which extends MultidexApplication, which will serve as the entry point of your application. 3-定义一个新类MyApplication,它扩展了MultidexApplication,它将作为应用程序的入口点。

public class MyApplication extends MultidexApplication

4- Finally, you should declare this new class in your AndroidManifest.xml 4-最后,您应该在AndroidManifest.xml中声明这个新类

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

<application
    android:name=".path-to.MyApplication">
    ...
</application>
</manifest>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 应用程序 apk 在手机上无法正常运行,但在模拟器上运行良好 - Flutter app apk does not work properly on phone but works well on emulator “ Package Installer已停止”-我的应用程序在仿真器和USB调试中工作正常,但内置的apk无法安装在真实手机上 - “Package Installer has stopped” - My app works fine on the Emulator and USB Debugging but built apk can't be installed on real phone Expo react-native 应用程序在手机上调试时工作,但发布的 apk 在启动时崩溃 - Expo react-native app works when debugging on phone but released apk crashes on start Ionic Android应用程序正常运行,但安装后无法运行 - Ionic Android app works but not apk when installed 开发Android 2.3.3应用程序,可在模拟器中运行,APK声称已安装在手机上,未安装任何软件 - Developing Android 2.3.3 app, works in emulator, APK claims it is installed on phone, nothing is installed Honeycomb 应用程序在模拟器和本地工作,但在我创建签名的 APK 时不起作用 - Honeycomb app works in Emulator and locally but does not work when I create the signed APK iOS 的 Flutter 应用程序:从计算机安装时,“评价我的应用程序”在设备上有效,但从 TestFlight 安装时无效 - Flutter app for iOS: 'Rate My App' works on device when installed from computer but does not work when installed from TestFlight Flutter:APK 安装在设备上时不会打开应用 - Flutter: APK does not open the app when installed on device 具有作为 AppBundle 分发的本机库的应用程序不起作用,但作为 APK 它可以工作 - App with native libs distributed as AppBundle does not work but as an APK it works 安装 apk 时出现“未安装应用程序”消息 - "App not installed" message when installed apk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM