It is not possible to allow actions for: Intent when test activity

I get errors when I try to run insturmentation tests on Android. I wrote an Activity called AudioPlayerActivity , which is in the package com.mycompany.mobile.android.gui, and now I'm trying to check the GUI of this project, and I am running the following error:

java.lang.RuntimeException: Unable to enable action for: Intent {act = android.intent.action.MAIN flg = 0x10000000 cmp = com.mycompany.mobile.android.gui / .AudioPlayerActivity}

I read this question and followed the advice there, but to no avail. I also searched for the error, but did not find any help.

Here's what my AndroidManifest.xml looks like for a test project:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.mobile.android.gui" android:versionCode="1" android:versionName="1.0" > <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.mycompany.mobile.android.gui" /> <application> <uses-library android:name="android.test.runner" /> </application> <uses-sdk android:targetSdkVersion="7" /> <supports-screens android:anyDensity="true" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest> 

And here is my Instrumentation test.

package com.mycompany.mobile.android.gui;

 import android.test.ActivityInstrumentationTestCase2; import com.mycompany.mobile.android.gui.AudioPlayerActivity; public class TestMusicPlayerActivityTest extends ActivityInstrumentationTestCase2<AudioPlayerActivity> { public TestMusicPlayerActivityTest() { super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); } public TestMusicPlayerActivityTest(String name) { super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); } public TestMusicPlayerActivityTest(String pkg, Class<AudioPlayerActivity> activityClass) { super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); } public void testSomething() { System.out.println("Nothing works :("); System.out.println(getActivity()); } } 

We run the whole process through maven, but this should not be part of the problem.

Proven activity, as you can see, also lies in one package. I do not call super-constructor activity instead of a package name, as most people having this problem do.

For your interest, this is AndroidManifest.xml describing the activity being tested:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.mobile.android.gui" android:versionCode="1" android:versionName="1.0" > <!-- omitted Uses permission + Uses SDK --> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:debuggable="true" android:theme="@style/NoTitleBar" > <!-- omitted other activities --> <activity android:name="com.mycompany.mobile.android.gui.AudioPlayerActivity" android:screenOrientation="portrait" ></activity> </application> </manifest> 

I also added activity to AndroidManifest.xml, but that didn't change anything. I also tried adding the MAIN / LAUNCHER intent filter for the desired activity, but this did not change the test result. I tried to start working with additional functions and without them, which also did not change the result.

+4
source share
2 answers
 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.mobile.android.gui" ... ... 

Do you use the same package name for your Android and Android project? This can be a problem, although I'm not sure if this is causing your java.lang.RuntimeException.

According to the official dev director here , your test project should have a different package name from your tested project:

The Android package name is the unique system name for the .apk file specified by the "android: package" attribute of the item in the package manifest. The name of the Android package of your test package must be different from the name of the Android package of the application under test. By default, Android tools create the name of the test package by adding ".test" to the package name of the application under test.

Try using the package name com.mycompany.mobile.android.gui.test for your test project.

+4
source

You run it as an Android project, try running it as an Android test project

adb shell am instrument -e package <java package> -w <test apk package> /android.test.InstrumentationTestRunner

0
source

Source: https://habr.com/ru/post/1390890/


All Articles