Google Play error: cannot upload a test-only APK
Asked Answered
Y

6

40

When trying to upload the first apk to a recently created project in GooglePlay console, I receive this error:

You cannot upload a test-only APK

Searching Google gives me 0 results for that exact string as per today.

I also have submitted a ticket for Play Console. Will update here if have any answer.

UPDATE Nov 29th 2017

As @paul-lammertsma suggested, there's a workaround. Still would be good to know why we need to go gradle way and we cannot do it via IDE.

Yerga answered 28/4, 2017 at 23:21 Comment(3)
Any news about the ticket from Google Play Console? AS 3.0 stable version is already released, and still seeing the error with the latest 3.1.0-alpha02 build. really strange.Interlay
Answer to your question < #47094054 >Gloam
@AngelKoh I cannot find any ticket submitted by me. I may have forgotten to do it at that time. We have a workaround now.. still would be nice to discover why this is not working as expected..Yerga
C
58

Building your app through Android Studio 3.0 and later will add android:testOnly="true" to your application manifest, marking the APK as FLAG_TEST_ONLY for the PackageManager. More information on CommonsBlog here.

Attempting to install such an APK outside of Android Studio will fail with:

Failed to install app-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Attempting to upload it to Google Play will also fail, with :

You cannot upload a test-only APK

There are four solutions to this:

Build from Android Studio

Simply select "Build APK(s)" from the "Build" menu in Android Studio.

Sign from Android Studio manually

Simply select "Generate Signed APK..." from the "Build" menu in Android Studio. Provide the keystore and enter the signing details in the dialog that displays.

Build through Gradle

You can of course simply execute Gradle from the terminal for some automation, for instance if your deployment cycle runs through CI (which I highly recommend!):

./gradlew assembleRelease

(Alternatively, you may prefer running this Gradle task from the Gradle pane from within Android Studio.)

Disable this feature in Android Studio

If you don't like this behavior, you may elect to add this flag to your gradle.properties. Beware that the test flag is for your own protection, so you don't accidentally publish a test-only APK!

# Disble testOnly mode for Android Studio
android.injected.testOnly=false
Conflux answered 19/7, 2017 at 16:10 Comment(9)
It worked for me with AS 3.0 beta2. Thanks Paul, you saved my dayTallu
It's true, if you build from Android Studio you'l get this error but works fine from the terminal. Just tested with Android Studio 3.0 beta 7, gradle-4.1, gradle plugin 3.0.0-beta7Showiness
Same thing with AS3 rc2Trina
The workaround works for me, as even AS 3.0 produced an APK causing the error.Thereunder
Accepting your answer as a workaround but still not happy taking this as a solution. IMO Android Studio should work as expected and not cause this trouble..Yerga
Google "wants you".... kotlin, gradle 3....Why not just focus on making their tools work. Honestly I've had enough...Tithonus
I didn't get solution, getting error while uploading on playstore.Tortricid
Solution is much simpler you should use Build apks rather than apks which you build from run buttonContour
As the user924 said, to solve this, in Android Studio, just click Build-> Build APK (s), and then send the new generated apkCircadian
Y
8

Looks like I found something very related: ADB Install Fails With INSTALL_FAILED_TEST_ONLY

I'm using 2.4.0-alpha6 of gradle plugin and that's seems to be far from ready to be used for production.

So the solution is to use the latest stable gradle plugin:

classpath 'com.android.tools.build:gradle:2.3.1'

Yerga answered 28/4, 2017 at 23:31 Comment(2)
If you're on AS3 Canary, be sure to downgrade the gradle AND the pluginLarose
...or upgrade to com.android.tools.build:gradle:3.0.0-beta2 ;)Meridel
G
8

Click on Build and then press BuildAPK(s) and then upload it will work. Instant run APK on android studio 3.0 runs only on the device attached to adb.

Gurgitation answered 6/11, 2017 at 4:40 Comment(0)
I
6

I found this blog that addresses the cause of the "test-only" bug

https://commonsware.com/blog/2017/10/31/android-studio-3p0-flag-test-only.html

basically, there are two things to note about it:

You cannot install an app with android:testOnly="true" by conventional means, such as from an Android file manager or from a download off of a Web site

Android Studio 3.0 sets android:testOnly="true" on APKs that are run from the IDE

android studio 3.0 now sets this "testOnly" flag when you compile a release version using the green Run button (make project CTRL+F9).

The solution I found is to not call "make project", but to call either

  • build > build APK or
  • build > Generate Signed APK...
Interlay answered 2/12, 2017 at 14:4 Comment(0)
T
2

I am using Android Studio 3.1 Canary 5

What I had tried (but not worked):

  • I tried all the answers as above,but Unfortunately I didn't get solution.
  • I removed kotlin dependency and signed but doesn't worked.
  • I tried use command line like ./gradlew assembleRelease
  • I tried to build apk using "Build APK" and "Generate Signed APK"

After all the possibilities I got solution by following way: - Compile SDK Version changed from Android P to Android Oreo 27 - Changed AppCompat Version to 27.0.1

and Its successfully working now.

Thank you.

Tortricid answered 24/3, 2018 at 12:35 Comment(0)
L
-1

It worked for me. Try to run this and build again. ./gradlew assembleRelease

Maybe You are uploading the wrong apk file which is generated previously not the signed apk. So select the apk file by locating the exact path of the generated signed apk file.

Langsyne answered 8/5, 2019 at 10:55 Comment(1)
what you say is already the accepted answer for this questionYerga

© 2022 - 2024 — McMap. All rights reserved.