[英]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.