how to find main activity in apk file for robotium tests

18,814

Solution 1

I know this is old but I happened to come upon it.

The question was: "I want to understand, how to identify MainActivity from the apk files?" As you should have the SDK and Build files on your box. Do the following:

Open up a command window/terminal

cd <SDK PATH>/build-tools/<BUILD TOOLS #>/

MAC/LINUX

./aapt dump badging <path to the APK file>

Windows

aapt.exe dump badging <path to the APK file>

Command Ref: badging Print the label and icon for the app declared in APK.

The Android Asset Packaging Tool (aapt) takes your application resource files, such as the AndroidManifest.xml file and the XML files for your Activities, and compiles them.

http://developer.android.com/tools/building/index.html

The output will be like this:

./aapt dump badging  ~/Documents/Projects/Eclipse/AndroidAutomation/Application/Project-debug-0.9.0.65.apk 
package: name='com.company.mobile.debug' versionCode='1' versionName='0.9.0.65-QADrop' platformBuildVersionName=''
sdkVersion:'15'
targetSdkVersion:'19'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
application-label:'Company-QADrop'
application-icon-160:'res/drawable-hdpi-v4/ic_launcher.png'
application-icon-240:'res/drawable-hdpi-v4/ic_launcher.png'
application-icon-320:'res/drawable-xhdpi-v4/ic_launcher.png'
application-icon-480:'res/drawable-xxhdpi-v4/ic_launcher.png'
application: label='Company-QADrop' icon='res/drawable-hdpi-v4/ic_launcher.png'
application-debuggable
launchable-activity: name='com.company.mobile.default'  label='' icon=''
feature-group: label=''
  uses-feature: name='android.hardware.screen.portrait'
  uses-implied-feature: name='android.hardware.screen.portrait' reason='one or more activities have specified a portrait orientation'
  uses-feature: name='android.hardware.touchscreen'
  uses-implied-feature: name='android.hardware.touchscreen' reason='default feature for all apps'
main
other-activities
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '240' '320' '480'

What you will want to look for is: "launchable-activity"

DONE!

I hope this helps someone.

J

Solution 2

In an android application there is always a main activity, but not only this activity may be launched. In one application there may be several activities, which you can launch separately. The main activity must have android:name="android.intent.category.LAUNCHER." In your example, the one and only main activity is: .activity.DropboxBrowser More information here (especially launch modes): http://developer.android.com/guide/topics/manifest/activity-element.html

Solution 3

This link gives us the perfect way to do it

http://code.google.com/p/robotium/wiki/RobotiumForAPKFiles

And in this when you will re-sign the apk with your re-sign.jar file it will tell you the name and activity of your apk file.

Solution 4

Decompile the apk file. Locate the AndroidManifest.xml file...open the file and find the first line starting with activity that consisting of intent-filter....this activity contains the main activity name normaly...in this code the main activity name is MainActivity

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lenovo.speech2sms">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS"/>


<application
    android:allowBackup="true"
    android:icon="@mipmap/app_icon_256"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Main2Activity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".Main3Activity"
        android:screenOrientation="portrait"/>
    <activity
        android:name=".Main4Activity"
        android:screenOrientation="portrait">
    </activity>
</application> 

Share:
18,814

Related videos on Youtube

user1835337
Author by

user1835337

Updated on June 21, 2022

Comments

  • user1835337
    user1835337 about 2 years

    I have a lot of apk files and I want to write simple tests with robotium for them. I have some problems, when I tried to find Main Activitys for them, in Dropbox app as example. In AndroidManifest.xml i found this:

    </activity> <provider android:name=".provider.ZipperedMediaProvider" android:exported="false" android:authorities="com.dropbox.android.ZipperedMediaProvider"></provider> <provider android:name=".provider.CameraUploadsProvider" android:exported="false" android:authorities="com.dropbox.android.CameraUploadsProvider"></provider> <activity android:theme="@android:01030055" android:name=".activity.DropboxBrowser"> <intent-filter > <action android:name="android.intent.action.MAIN"></action> <category android:name="android.intent.category.LAUNCHER"></category> </intent-filter> <intent-filter android:label="Dropbox File Browser"> <action android:name="com.dropbox.BROWSE"></action> <action android:name="android.intent.action.VIEW"></action> <action android:name="android.intent.action.EDIT"></action> <category android:name="android.intent.category.DEFAULT"></category> <data android:mimeType="vnd.android.cursor.dir/vnd.dropbox.entry"></data> <data android:mimeType="vnd.android.cursor.item/vnd.dropbox.entry"></data> </intent-filter> </activity>

    How to understand how main activity is called? I'm useing ApkAnalyser and I tried different classnames and other strings, but robotium test can't launch app and write that there are no tests in my project:/ (apk is re-signed in my PC) I want to understand, how to identify MainActivity from th apk files? thx

  • maszter
    maszter over 11 years
    not exactly, "android.intent.category.LAUNCHER" is most important
  • Paul Harris
    Paul Harris over 11 years
    He specifically mentioned the MainActivity i assumed he meant the activity with the main action. Main action is a special case even more so than Launcher activity because it requires no intent information in order to launch the application normally (completely clean state). True he could launch other activities that are not main and just Launcher but that might not work correctly like he believed it might do and would depend on the developer. It also has special uses with the google play store. developer.android.com/guide/components/intents-filters.html
  • Colin
    Colin over 9 years
    and as for a way to view this information for an apk file, use "aapt dump badging DropboxBrowser.apk | grep activity"
  • m0skit0
    m0skit0 almost 9 years
    For scripting or people that don't want to look through the whole AAPT dump: aapt dump badging /path/to/apk/ApkName.apk | grep launchable-activity | sed -r "s/launchable-activity: name='([a-z0-9.]*)'.*/\1/i"
  • João Ciocca
    João Ciocca over 2 years
    Robotium seems like it's been abandoned, last update 5 years ago =(