9

I use Eclipse for develop android apps, but when run projects see this error:

Installation failed due to invalid APK file!

davidcesarino
  • 16,160
  • 16
  • 68
  • 109
AbbasS
  • 99
  • 1
  • 1
  • 6
  • possible duplicate of [invalid APK file](http://stackoverflow.com/questions/4710363/invalid-apk-file) – Ray Nov 03 '11 at 17:49
  • Refer this http://stackoverflow.com/questions/13617440/installation-failed-due-to-invalid-uri-installs-only-in-debug-mode/20279665#20279665 – Sampath Kumar Nov 29 '13 at 06:29

10 Answers10

8

One of the most common reasons we see "Invalid APK file" error is due to inadvertently changed AndroidManifest.xml configuration, which results in installing duplicated APK files on your device.

Posibility 1: version problem. Make your minimum and target sdk version higher and try again.

Posibility 2: package mistmatching. Package name in AndroidManifest.xml does not match with the actual package that your activity is associated with.

Three steps to solve this problem:

Step 1. Check your header file from your AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourdomain.yourapp"
    android:versionCode="1"
    android:versionName="1.0" >

Step 2. Confirm that your package name in your src folder is exactly the same as the one you verified in Step 1.

e.g. com.yourdomain.yourapp

Step 3. Check your package inclustion statement from your launcher activity (e.g. MainActivity.java):

package com.yourdomain.yourapp;

If the aforementioned solutions are not working, please post your Logcat for further assist.

melvynkim
  • 1,655
  • 3
  • 25
  • 38
8

In my case this was caused by errors in a .jar file included my library. The .jar file was one I created and so I was able to fix it. Here is a breakdown of how the problem started and how I fixed it:

  • I made changes to another project(not the project that failed to install)
  • Exported to a .jar included ALL files in project(which was the mistake)
  • the resulting .jar replaced the one already included in my project
  • Errors occurred

to fix it:

  • Re-exported .jar file including only the src folder
  • re-built and installed just fine.

Having included all the files that were not part of the src folder caused a few duplicates in the project and .jar:

  • Example: multiple androidmanifest.xml files one local and one inside .jar

This caused the .apk to be invalid. Hope this helps someone. NOTE: this solution will only work if you have library files that you have changed and compiled yourself and have made the same mistake as I did when I included folders that were not needed.

ProgMasta
  • 141
  • 1
  • 8
  • How was the apk invalid after that? In my case it's not a valid zip file! I'm using both NDK libraries and non NDK library (cardboard.jar) in my project. – Csaba Toth Jan 25 '16 at 00:39
3

Totally agree with @melvkim answer. One thing to add.

Also please make sure that you do not use forbidden characters in your package name. E.g.:

Wrong package names

  • com.domain.365days - you cant start any part of package name with a digit (...)
  • com.domain._365days - (...) nor a special character

Correct package names

  • com.domain.days365 - start all parts of your package name with a letter

Please see your logcat very carefully. Eclipse IDE might not show any error or warning, but logcat will.

marekozw
  • 356
  • 2
  • 7
  • 1
    This was totally my problem. Thanks for pointing this out. I should have figured out where to check logcat also. This is an unfortunate restriction, because in plain old Java, you are allowed to start your package name with a special character like _, which is recommended if you have a company whose name starts with a number, like say 360 Engineering. This is now an unfortunate inconsistency if said company's IT department wrote a bunch of Java classes with packages starting com._360 or com._360engineering and now has to have Android classes starting com.engineering360 .. – Michael Plautz Nov 06 '14 at 12:33
  • Yes, this restriction is very inconvenient. Anyway, I'm glad my comment was helpful. – marekozw Nov 10 '14 at 09:39
3

Try this over ADB:

cd /data/local
mv tmp tmp-old
mkdir /mnt/sdcard/tmp
ln -s /mnt/sdcard/tmp ./tmp
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

For me it was a different problem causing this error:

My project was using some native JNI libraries embedded to the APK. To save some space during tests, I disabled the lib\armeabi version, leaving only the newer lib\armeabi-v7a variant. All went fine on newer devices, but testing it on the older G1 resulted in this error.

radhoo
  • 2,877
  • 26
  • 27
0

Check your Platform version on Phone or Emulator (depend where you're testing ) must be same or greater then the version you mentioned in your AndroidManifest.xml.

RO N
  • 1
  • 3
0

In my case, I solved the problem by changing my AndroidManifest.xml

I changed from

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

to

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="20" />

because eclipse gave me an warning for nor targeting the latest version of Android.

I'm using the latest Eclipse SDK v23 and my device is Nexus 7 2012 KitKat 4.4.4

Bolun Zhang
  • 148
  • 1
  • 10
  • Later I changed from 20 to 19 to reproduce the problem, but failed. The problem didn't occur again, which I don't understand. Because I'm sure changing AndroidManifest.xml was the only thing i had done and it solved the problem. – Bolun Zhang Jul 14 '14 at 15:02
0

In my case, the issue was due to mis-match in the Android manifest file and Project Build Target API Level

I changed from targetSdkVersion from 19 to 21.

Also, by changing the target sdk version through the stepsgiven below

  1. right click on project name
  2. select properties
  3. change "Project Build Target" to API Level 21
0

For me, the problem was that I was using the wrong path to the file of interest. In other words, the apk file did not exist! Why couldn't the darn thing just tell me that it couldn't find a file? Argh! Ah well. Maybe this will help someone else. Double check to make sure that your path to the file is correct!

0

I am sure this is the version problem. First check whether your emulator/phone is having correct version that you are developing for.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • i can install android app developed by basic4android fine. but eclipse can't do it. C:\AndroidSDK\platform-tools\aapt.exe crunch -v -S C:\Users\Dev\workspace\GPS\res -C C:\Users\Dev\workspace\GPS\bin\res – AbbasS Nov 04 '11 at 10:23
  • Please check logcat output for more details. – AbbasS Nov 04 '11 at 10:23