The application could not be installed. Installation failed due to: 'Invalid File: <path>.apk

Viewed 1097

I am trying to run the app on Note8 device using Android Studio and facing this issue after updating the variant output Directory path inside app/build.gradle file. There are lot of similar kind of issues I have seen, but none of their solutions are working for me.

I am on Android studio 3.6.+ and note 8 device, Also the funny things is path it's showing doesn't exist currently, it is the old path for variant.output in my app/build.gradle file.

changes after which the error started:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputDir = new File("${project.buildDir.absolutePath}/outputs/apk")
        def outputFileName = "DEMO-${variant.flavorName}-Build-${versionName}.apk"
        variant.packageApplicationProvider.get().outputDirectory = new File("$outputDir")
        output.outputFileName = outputFileName
    }
}

before changes: outputDir is the where it's showing the file is missing error.

def outputDir = new File("${project.buildDir.absolutePath}/outputs/apk/${variant.flavorName}/${variant.buildType.name}")
def outputFileName = "DEMO-${variant.flavorName}-${variant.buildType.name}-${versionName}.apk"
        

Things I have tried so far: I have tried clean and rebuild project, I have tried invalid cache and restart, I have tried deleting .idea, cache and .build directories, Also I have no application with the same package name already installed in my device.

Could some one suggest the possible cause and how to resolve it?

3 Answers

if cleaning, rebuilding and invalidating cache and deleting build folder inside app directory don't work

try this one

File > Settings > Build,Execution,Deployment > Instant Run > uncheck 'Enable Instant Run to hot swap code'

For those who might still be having this problem, You can cleaning, rebuilding and invalidating caches does not work, couple of things to try,

  1. Upgrade Your gradle build version to the latest version.
  2. If your code is kolin, check Kotlin version used for building with Gradle is same from the one bundled into the IDE plugin. Upgrade to that bundled into the IDE

Then sync, this worked for me.

You may try it:

File >> Invalidate Caches and check two options

  • Clear file system cache and Local History
  • Clear VCS Log caches and indexes

Then,

Build >> Clean project
Build >> Rebuild project

Now Run you code.

Related