I have some requirements where I should run the test project anytime on my device, without connecting it to system and running through eclipse.
I added some intent-filter to my AndroidManifest.xml to make the test project visible on the launcher, however, it never runs successfully and is not able to find the target activity class
Meanwhile, If I connect the device to system, and from eclipse perform Run As Android Junit , it runs successfully without any exception. So what is wrong here? Am i missing some concept ?
Below is the AndroidManifest.xml of my test application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.org.search.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="18"/>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.third.party.packageName" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="android.test.runner" />
<activity android:name="com.org.search.test.MyTestClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is the exception log
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.third.party.packageName.SearchActivity
at com.expedia.search.test.ExpediaHotelsScraper.<clinit>(ExpediaHotelsScraper.java:35)
... 15 more
Caused by: java.lang.ClassNotFoundException: com.third.party.packageName.SearchActivity
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at java.lang.Class.forName(Class.java:169)
at com.org.search.test.MyTestClass.<clinit>(MyTestClass.java:32)
... 15 more
Caused by: java.lang.NoClassDefFoundError: com/third/party/packageName/activity/SearchActivity
... 19 more
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.third.party.packageName.SearchActivity" on path:
DexPathList[[zip file "/system/framework/android.test.runner.jar",
zip file "/data/app/com.org.search.test-1.apk"],
nativeLibraryDirectories=[/data/app-lib/com.org.search.test-1,
/vendor/lib, /system/lib]]
Also the test class code MyTestClass.java
public class MyTestClass extends ActivityInstrumentationTestCase2 {
private static final String LAUNCH_ACTIVITY_NAME =
"com.third.party.packageName.activity.SearchActivity";
private Solo solo;
private static Class<?> splashActivityClass;
static {
try {
splashActivityClass = Class.forName(LAUNCH_ACTIVITY_NAME);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public MyTestClass() throws ClassNotFoundException {
super(splashActivityClass);
}
#Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testAllCountries() {
//my test goes here
}
I am new to android automation. Please help me understand the concept if am trying something infeasible.
You should read Android Testing: running tests from code which would help you in achieving your objective.
Related
I am trying to test the tic-tac-toe in eclipse. It compiles and deploys to emulator device (AVD) but no matter what version of Android I use, the application deployed says: Application Stopped. Close it. Is there any specific setting I should follow?
Note: I already setup the Eclipse environment, add libraries, etc.
Thanks!
Here is the log error:
01-16 01:07:35.994: E/AndroidRuntime(883): FATAL EXCEPTION: main
01-16 01:07:35.994: E/AndroidRuntime(883): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.cast.samples.tictactoe/com.google.cast.samples.tictactoe.GameActivity}: java.lang.ClassNotFoundException: Didn't find class "com.google.cast.samples.tictactoe.GameActivity" on path: DexPathList[[zip file "/data/app/com.google.cast.samples.tictactoe-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.cast.samples.tictactoe-1, /system/lib]]
01-16 01:07:35.994: E/AndroidRuntime(883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
01-16 01:07:35.994: E/AndroidRuntime(883): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-16 01:07:35.994: E/AndroidRuntime(883): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-16 01:07:35.994: E/AndroidRuntime(883): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.cast.samples.tictactoe.GameActivity" on path: DexPathList[[zip file "/data/app/com.google.cast.samples.tictactoe-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.cast.samples.tictactoe-1, /system/lib]]
01-16 01:07:35.994: E/AndroidRuntime(883): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
Thanks Ali. Here is the manifest, but I see there is a match of class and activity.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.cast.samples.tictactoe"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:name="android.hardware.wifi"
android:required="true" >
</uses-feature>
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat" >
<activity
android:name=".GameActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Exception states that it didn't find your GameActivity class. Check your Manifest and see if the name given there as the launcher activity (GameActivity) matches with the class that you have in your package, check the package names, etc. The exception has nothing to do (at least the piece that you have shown) with Cast.
Thanks for all the help. I solved by silly configuration. I created a libs folder and copied under GoogleCastSDKAndroid.jar (marked as Private Library). Compiled and it worked perfect!
Now, I just learned the casting function can't work because AVD runs a different IP address (in my case registered a 10.0.2.15) than my wifi segment (192.168.1.x). Therefore, the AVD can't see a chrome device.
I hope this last conclusion helps other people. The first was a mistake of configuration.
i am running one android application in which i am using ActionBar but from supported library for android 2.2
i have added two external jar file as a support libraries
android-support-v7-appcompact.jar
android-support-v13.jar
but when i run the sample in my device i getting following runtime error
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.NavMainActivity}:
java.lang.ClassNotFoundException:
com.example.android.navigationdrawerexample.NavMainActivity in loader
dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-1.apk]
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:143) at
android.app.ActivityThread.main(ActivityThread.java:4914) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:521) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at
dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.NavMainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1033)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
here is the menifest file content
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.navigationdrawerexample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
>
<activity android:name="NavMainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
order of jar files
You should not only look at errors but also at warnings (orange text color in eclipse logcat view). Dalvik class loading are often preceded by some interesting informations about why a class can't be loaded by the Dalvik, something like a super class not existing.
I am trying to get Google Maps Android API v2 working on Android 2.2 on a HTC Desire.
My main.xml contains the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my activity.
package dk.sw510e13.user;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
When I run the application, I will get the following exception. It seems that it cannot find SupportMapFragment, however, I believe that I have both the support library and Google Play Services as dependencies. When creating the project in Android Studio I chose to add support for fragments.
01-17 23:52:55.237 2557-2557/dk.sw510e13.user E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.sw510e13.user/dk.sw510e13.user.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
at android.app.Activity.setContentView(Activity.java:1654)
at dk.sw510e13.user.MainActivity.onCreate(MainActivity.java:13)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/data/app/dk.sw510e13.user-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
... 23 more
This is what I have in my dependencies.
Can anyone tell me what I am doing wrong?
UPDATE
This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXXXXX"/>
</application>
</manifest>
This is the problem that seems to be occurred when missing Google Play services.
I request you to please follow the steps mentioned below to get the Google Play services to be included in your application.
copying the google-play-services.jar in libs folder and set in the build path of eclipse is a wrong method.
import Google Play services in your project and add it in workspace.
from location of your SDK folder.
\extras\google\google_play_services\libproject\google-play-services_lib
2! Now you added Google Play Services to your work space, we have to create a reference
from our project to this library. Right-Click your project and choose “Properties” go
to the Android section, in the lower part press the “Add…” button and add a reference
to that library. Your result should be as in the screen shot bellow:
adding Google Play services library
Please Add
<permission
android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
in your manifest
I need to use actionbarsherlock in my test project. Here is my activity:
public class MainActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
}
and this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlocktest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbarsherlocktest.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
but when I run as an android application, it is said:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:998)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
at com.example.actionbarsherlocktest.MainActivity.onCreate(MainActivity.java:12)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
can someone help me?
This seems to be a problem in how you have your project and its libraries configured. The compiler is unable to find the auto generated R class for ABS which probably means it's just not being generated. You should try reimporting ABS into your project. This video on how to get started with the library might help: http://www.youtube.com/watch?v=4GJ6yY1lNNY.
Have you imported the libraries properly?
Well try this ! this might help you:
Libraries do not get added to APK anymore after upgrade to ADT 22
I get the following error from the emulator in Eclipse when I run an Android application...
"The application has stopped unexpectedly. Please try again"
There are no error icons appearing in the project folder in Eclipse. I have already tried...
Cleaning the Project
Android Tools > Fix Project Properties
Updating the Build Path
My Error Log is saying...
"java.lang.RuntimeException: Unable to instantiate activity ComponentInfo..."
The Error Log goes onto say...
"Caused by: java.lang.ClassNotFoundException..."
Just to note that I do not have a "Build.xml" file in my project folder but instead a "apktool.yml" if this makes any difference.
Any suggestions??
EDIT:
Here's the manifest file...
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="61" android:versionName="1.2.2" package="com.__.__"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:label="#string/app_name" android:name=".MTActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".RCActivity" android:screenOrientation="portrait" />
...
Errors generated LogCat...
E/AndroidRuntime(6220): FATAL EXCEPTION: main
E/AndroidRuntime(6220): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ir.mtools/com.ir.mtools.MTActivity}: java.lang.ClassNotFoundException:
com.irtza.pulmtools.MTActivity in loader dalvik.system.PathClassLoader[/data/app/com.ir.mtools-1.apk]
E/AndroidRuntime(6220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
E/AndroidRuntime(6220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
E/AndroidRuntime(6220): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(6220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
E/AndroidRuntime(6220): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(6220): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(6220): at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(6220): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(6220): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(6220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
E/AndroidRuntime(6220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
E/AndroidRuntime(6220): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(6220): Caused by: java.lang.ClassNotFoundException: com.ir.mtools.MTActivity in loader dalvik.system.PathClassLoader[/data/app/com.ir.mtools-1.apk]
Whenever this happens it means your application has encountered a runtime exception, which means no errors will show up at compile time. In this case I'm guessing you have not declared the activity in the AndroidManifest.xml file, but without seeing more code that's only a guess.
java.lang.ClassNotFoundException: com.ir.mtools.MTActivity
Is com.ir.mtools.MTActivity this part of some library? if so have you included it in your build path ?