Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

android - Google Play error: cannot upload a test-only APK

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...