繁体   English   中英

Android Studio 不生成 APK

[英]Android Studio not generating APK

我有一个奇怪的问题,刚从现有的 Android Studio 2.3.3 项目开始。

构建过程不会自动生成 APK,在这种情况下 app-debug.apk 日志显示构建成功,但项目目录树中的任何位置都没有 APK。 但是,手动选择 Build / Build APK 工作正常。

当我更改源并单击运行时,这是一个问题。 构建过程成功,但随后在模拟器中出现“错误安装 APK”(因为 APK 不存在)。

这个问题只发生在一个项目上,我之前在玩 Espresso。 我的猜测是我在某处更改了设置,我只是不知道是哪一个。 我需要更改什么才能再次自动生成 APK? 包括 build.gradle。

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.example.myapp"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 2
    versionName "0.0.2"
    vectorDrawables.useSupportLibrary = true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
    release {
        storeFile file("/home/user/keystore/keystore.jks")
        storePassword "xxxxxxxxxxxxxxxxxx"
        keyAlias "xxxxxxxxxxxxxxxxx"
        keyPassword "xxxxxxxxxxxxxxxxxxx"
    }
}

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
lintOptions {
    abortOnError false
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.android.gms:play-services-location:10.2.4'
testCompile 'junit:junit:4.12'
}

尝试以下解决方案 -

在 Android Studio 的右侧,您有一个 gradle 选项,单击它,然后单击刷新图标,然后检查构建。

更多详情请点击以下链接 -

apk 没有生成

由于Build.gradle android studio 中的很多依赖,花费了太多时间然后说 Request time out。 所以看看Build.gradle 做这些步骤。

第一种方法:尽量减少依赖

第二种方法:为 androidX 添加 MultiDEX implementation 'androidx.multidex:multidex:2.0.1'

第三种方法:将类设为public class ApplicationDelegate extends MultiDexApplication { }然后在 Application 标签中像这样添加 Android Manifest File

<application
        android:name=".ApplicationDelegate"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">


Hope it will solve your issue!



我的 Android Studio 一直这样做,所以我想出了一个解决方法。 而不是去构建>构建APK。 我只是运行应用程序。

运行应用程序后,如果您转到项目目录中的 build > output > apk,您将在那里找到您的 APK。 当您运行应用程序时,Android Studio 很少会抛出错误。

编辑此 APK 在物理设备上不起作用我不知道是什么原因。 虽然它在模拟器上运行。

密钥有问题,也许它不在路径上......工作室不会报告任何内容(只是不构建捆绑包)。 单击密钥别名字段中的文件夹图标,如果密钥不在路径上(最快检查),则会出错。

快乐编码

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM