4

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

Greg
  • 16,359
  • 2
  • 34
  • 44
user1835337
  • 656
  • 1
  • 9
  • 32

6 Answers6

12

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

JulianHarty
  • 3,178
  • 3
  • 32
  • 46
JamesDeHart
  • 245
  • 2
  • 9
  • 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"` – m0skit0 Aug 03 '15 at 11:03
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

Colin
  • 2,089
  • 25
  • 34
maszter
  • 3,680
  • 6
  • 37
  • 53
  • and as for a way to view this information for an apk file, use "aapt dump badging DropboxBrowser.apk | grep activity" – Colin Oct 22 '14 at 17:30
1

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.

Saurabh B
  • 165
  • 10
1

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> 

Mohammed Javad
  • 163
  • 1
  • 11
0

The main activity is defined in the XMl you have above, it will be linked to an intent filter for main.

in the case of the above code it will be contained in the following:

which tells me the activity is ".activity.DropboxBrowser".

the "." at the beginning means you need to append whatever the package name for the application is before so it will be something like "xxx.xxx.activity.DropboxBrowser" where xxx.xxx is the packagename defined at the top of the android manifest (or you can look it up with pacakagemanager)

Paul Harris
  • 5,769
  • 1
  • 25
  • 41
  • not exactly, "android.intent.category.LAUNCHER" is most important – maszter Mar 19 '13 at 16:23
  • 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. http://developer.android.com/guide/components/intents-filters.html – Paul Harris Mar 19 '13 at 16:31
0

To gain a time (if you want testing over 100 apk), you have to automatise this identification steps.

For this, you can parse Manifestfile and only select Activity that handle intents composed with android.intent.action.MAIN action and the category android.intent.category.LAUNCHER.

inspiration of parsing : com.android.ide.common.xml.AndroidManifestParser

xena
  • 31
  • 3