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

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.

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

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'

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.

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

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.

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.

Related

Run button isn't compiling project in Android Studio 3.1 [duplicate]

When I try to install an app, there are two possibilities:
Install existing APK from build folder when I run the app
Install APK after performing clean build
For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:
The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.
NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder
I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.
Things I've tried:
Running the app when APK file exists in the build folder (works perfectly fine)
Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
Same process of cleaning and running the app after doing Invalidate Caches/Restart
I have solution for your issue.
Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768
Edit your app configuration as below.
Here you can see your app configuration as below.
Here is missing Gradle-aware make attribute in before launch configuration. You can see here.
Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.
You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.
It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.
Note : This issue is resolved in new Android Studio 3.1.1 Stable release.
The APK file
/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not
exist on disk.
May be bug. You should change Settings.
You should open the Run/Debug Configurations dialog & select Run > Edit Configurations
Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.
Note
If you receive
Shutdown finished in 0ms Error while generating dependencies split APK
com.android.ide.common.process.ProcessException: Failed to execute
aapt at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
at
com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)
You should Un-Check INSTANT RUN.
File-- Settings-- Build, Execution, Deployment -- Instant Run and
uncheck Enable Instant Run.
clean your project and run again
If it's not work then
Step 1 Close your project.
Step 2 Go to your project folder and delete all build folder.
Step 3 run your project.
This issue has been fixed with Android studio 3.1.1 (April 2018) release.
Update your android studio to 3.1.1.
Here is there explanation regrading the issue details, cause and solution:
In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.
To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.
Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0
For all people seing this and having the issue on Android Studio +4.0.0:
Run -> Edit configurations... -> disable check box (Allow parallel run)
It may slow your build a little but it better than running the app more than one time.

Android Studio 3.1 is not compiling/building the app, runs instantly [duplicate]

When I try to install an app, there are two possibilities:
Install existing APK from build folder when I run the app
Install APK after performing clean build
For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:
The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.
NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder
I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.
Things I've tried:
Running the app when APK file exists in the build folder (works perfectly fine)
Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
Same process of cleaning and running the app after doing Invalidate Caches/Restart
I have solution for your issue.
Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768
Edit your app configuration as below.
Here you can see your app configuration as below.
Here is missing Gradle-aware make attribute in before launch configuration. You can see here.
Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.
You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.
It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.
Note : This issue is resolved in new Android Studio 3.1.1 Stable release.
The APK file
/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not
exist on disk.
May be bug. You should change Settings.
You should open the Run/Debug Configurations dialog & select Run > Edit Configurations
Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.
Note
If you receive
Shutdown finished in 0ms Error while generating dependencies split APK
com.android.ide.common.process.ProcessException: Failed to execute
aapt at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
at
com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)
You should Un-Check INSTANT RUN.
File-- Settings-- Build, Execution, Deployment -- Instant Run and
uncheck Enable Instant Run.
clean your project and run again
If it's not work then
Step 1 Close your project.
Step 2 Go to your project folder and delete all build folder.
Step 3 run your project.
This issue has been fixed with Android studio 3.1.1 (April 2018) release.
Update your android studio to 3.1.1.
Here is there explanation regrading the issue details, cause and solution:
In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.
To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.
Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0
For all people seing this and having the issue on Android Studio +4.0.0:
Run -> Edit configurations... -> disable check box (Allow parallel run)
It may slow your build a little but it better than running the app more than one time.

Can't run app with Instant Run on Android Studio 3.0

I've updated to Android Studio 3.0 and now I cannot run the app with Instant Run enabled.
I get 'Execution failed for task' due to a java.io.FileNotFoundException because it can't find the apk under
../build/intermediates/instant-run-resources/resources-production/
Any idea how to overcome this so that I can run the project with Instant Run?
I'm not sure where to find the missing apk file or how to change the path to look for it in.
Have your settings as below,
Otherwise try to clean and re-install (after uninstalling exsisting apk) application.
I found the problem and the solution.
In my case the cause was dexcount-gradle-plugin. The plugin is expecting that the package task produces an APK, but that is not true anymore on Instant Run. So they released a new version that disables the process when running with Instant Run.
So I just had to update dexcount to the latest version.
Configure your project for Instant Run
Android Studio enables Instant Run by default for projects built using Android plugin for Gradle 2.3.0 and higher.
Please checkout this LINK to configure your project for instant run.

INSTALL_FAILED_TEST_ONLY in Android studio 2.4 preview 7

I'm using Android Studio 2.4 preview 7 version. But, when I build debug apk and install via adb command or put apk file in sdcard of device it always gives me same error "App not installed" in any of android phone. I have got INSTALL_FAILED_TEST_ONLY error in Android Logcat every time at the time of installation in any android device.
If you analyze your apk file you'll see the problem easily - namely that when building the project with the mentioned Android Studio version, the Gradle plugin is automatically injecting an android:testOnly=true to the final AndroidManifest.xml file of the output apk.
You can read more about this property and what it's used for HERE.
To workaround this problem - you can still install the app using this command:
adb install -t debug.apk
If you want to build a signed release version of your app (e.g. for publishing the Play Store), you can always do so via Build -> Generate Signed APK. The result is an apk without the mentioned property and can be installed on any device.
If you want a bit of context why this property is injected, perhaps check THIS and THIS issues on the AOSP bug tracker.

cordova 5.0 generate signed apk

I use Cordova 5.0.0 to develop android app and I would like to run the app on real machine.
I tried two ways to generate signed apk but failed,
One is used command line to sign an apk that generated by cordova. by this way, it will cause "parsing error" when install the apk;
The second way I tried is using android studio to generate signed apk. My step is "import non-android studio project" then generate signed apk. By this way, I install successfully but the app can't be open and popup error info "unfortunately, xx has stopped".
There is no problem with the code.
Anyone can give me some suggestion? Thanks.
Cordova 5 uses gradle to compile now, so the old ant.properties no longer works. You can work the same trick by creating a release-signing.properties file in platforms/android and adding the following:
storeFile=<path to="" .keystore="" file="">
storeType=jks
keyAlias=<your key="" alias="">
// optional :
keyPassword=<your-key-password>
storePassword=<your-store-password>
If you used Android Studio, you can try with Intellij IDEA (Android Studio is performed by Intellij Platfrom ) here.
After importing your projet, simple go to :
Build > Generate Signed APK..
You'll need to create a key and then Intellij will create your APK.
If you still have your error "unfortunaly..." connect your device and check Intellij logs.

Categories

Resources