简体   繁体   中英

Android Studio not generating APK

I have a strange problem that just started with an existing Android Studio 2.3.3 project.

The build process is not automatically generating an APK, in this case app-debug.apk Log shows build is successful, but no APK anywhere in the project directory tree. Manually selecting Build / Build APK works fine, however.

This is a problem when I change the source and click run. The build process is successful, but then get "Error Installing APK" into the emulator (because the APK does not exist).

This problem only happens on the one project, and I was playing around with Espresso earlier. My guess is I changed a setting somewhere, I just cannot figure out which one. What do I need to change to have the APK generated automatically again? build.gradle included.

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'
}

Try below solution -

At right side of Android studio you have a gradle option click on that and then click the refresh icon and then check build.

More details follow below link -

apk not generating

Due to many dependencies in Build.gradle android studio takes too much time and then said Request time out. So have a look into Build.gradle . Do these steps.

First Method : try to minimize the dependencies

Second Method : Add MultiDEX implementation 'androidx.multidex:multidex:2.0.1' this is for androidX.

Third Method : Make class public class ApplicationDelegate extends MultiDexApplication { } then add in Android Manifest File like this in Application tag

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



My Android Studio does it all the time so I came up with a workaround. Instead of going to Build > Build APK. I simply run the app.

After running the app if you go to build > output > apk in your project directory, you will find your APK over there. Android Studio rarely throws an error when you run the app.

EDIT This APK does NOT work on physical devices I dont know what the reason is. It runs on emulators though.

Something is not right with the key, maybe it is not on the path... A studio does not report anything then (simply does not build bundle). Click on the folder icon in the key alias field it will be an error if the key is not on the path (fastest check).

Happy codding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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