To use Android Support Fragment v4 in Robolectric 3.0 you must add gradle dependency in /app/build.gradle
Then import into your Robolectric testing java class
then you can create/start android support v4 fragments within your Robolectric testing java class for unit testing:
Cross posted to StackOverflow Android Robolectric Support Fragment.
Begin typing foreach until autocomplete pops up. Select “Create a for each loop”.
You’ll then get an empty for each loop that you can start filling in, first supplying the Type of each object, a variable name of your choice for that object, then hit Enter to move to the name of the variable (a Collection), then hit Enter, then supply the statements you wish to run against each item within the collection.
To Pause genymotion Android Emulator on Mac:
- Press the power button of emulator (bottom right corner)
- This is equivalent to executing “avd stop” within adb shell on the emulator
- Find the process ID number of VBoxHeadless using Activity Monitor
- In Terminal: kill -STOP <ID number from step 2>
- Your emulator is now effectively paused and uses no CPU
To Restart / Unpause Android Emulator
- In Terminal: kill -CONT <ID number from step 2 above>
- Press the power button on emulator (bottom right corner of window)
- Your emulator is now restarted & should operate normally
Android Studio (app) build.gradle sourceSets androidTest java.srcDir property may not be recognized when using the array format of this source directory property setting.
java.srcDirs = ['androidTest/java']
For setting up Robotium UI / Integration testing, it’s important that your androidTest source directory is recognized.
Failed to Find Build Tools Revision 2X.X.X
Android Build tools get updated often and whenever an Android project you import that is using a different Build Tools Revision than the one you’re using, you’ll see this error in Android Studio.
To fix “Failed to Find Build Tools Revision” you have 2 options:
- Install the missing Build Tools revision
- Change the Build Tools version in your ../app/build.gradle
Install missing Android Build Tools revision
Install a missing Android Build Tools revision via Tools -> Android -> SDK Manager -> SDK Tools (tab) -> Check Show Package Details (bottom right check box) -> mark the checkbox of the requested Android Build Tools version
Change the Android Build Tools Version in Build.Gradle
- Open app/build.gradle
- Find buildToolsVersion
- Change the version number to one you have installed (see above SDK Tools image on how to find which versions you have installed, which are marked as “Installed” or “Not Installed”)
- Sync Gradle.
In Project Explorer:
- Right click on Gradle project
- Refresh All
New dependencies should be downloaded and project refreshed.
Java import statements for new Gradle project dependencies should work after this.
How to add a java Gradle Project into an existing Eclipse project
Start by importing your required Java Gradle projects into Eclipse’s Project Explorer.
Highlight your main project in Project Explorer.
This is the project you want to add a Gradle java project to (so you can use import statements on packages found in the other Gradle project).
On the Main toolbar menu go to
Project > Properties > Java Build Path > Projects (tab) > Add (button)
A list of projects in the current Project Explorer will show up in a window.
Select the java project that you wish to use within your main project, that is not already on the Build Path.
Eclipse should refresh / rebuild automatically and check for import statements for references to the newly added project from your main project.
How To Kill Tomcat on Mac when IntelliJ IDEA or Eclipse has crashed or you forgot to stop Tomcat before closing Eclipse.
Step 1: find which java process is Tomcat
- Start Activity Monitor (Applications > Utilities), then order list by Process name
- Scroll to find java processes
- Note the PID #’s (process ID’s)
Step 2: Pause java processes while checking Tomcat address
- From a browser load your normal Tomcat address, e.g. http://localhost:8080/
- You should get some sort of response, perhaps a Whitelabel Error page if using Spring
- repeat below until Tomcat stops responding:
- pause java PID using: kill -STOP <PID>
- replace <PID> with the actual process ID # you found from Activity Monitor
- example: kill -STOP 25532
- reload Tomcat web address
- if web page no longer responds (just continues to load), you’ve found Tomcat
- otherwise (wasn’t Tomcat), unpause process: kill -CONT <PID>
- example: kill -CONT 25532
- move to next process ID number in Activity Monitor with name “java” and repeat steps
Step 3: Kill Tomcat on Mac
- kill the Tomcat java process in Terminal using command: kill -9 <PID>
- Check: Reload Tomcat webpage in browser. Should show “This webpage is not available”
Android security fix MMS flaw – Turn Off MMS Message Auto retrieve.
Below is only a workaround for Android’s MMS Security Flaw (aka Stagefright)
Please update your Android phone ASAP. There are several other flaws related to Stagefright that this workaround will not help!
Android Security Fix Steps
Step 1 – Hangouts or Messaging
If you’re using Google Hangouts for SMS/MMS, open Hangouts app. (For Messaging app?)
Step 2 – Settings
Click on Settings
Step 3 – SMS
Click on SMS
Step 4 – Multimedia (MMS) Messages > Auto retrieve MMS = OFF
(Click to) remove the checkbox from Auto retrieve MMS. You’re done.
Stagefright flaw in Android exploits how Android’s MMS (Multimedia Messages) system automatically downloads MMS content (e.g. video) to be read / cached locally, without any user interaction. This automatic reading of the MMS content allows attackers to embed their virus / trojan payload into a video which will automatically be run by Android’s Content Provider / Stagefright system.
This Google Android Vulnerability MMS Flaw was found by Joshua Drake (twitter) of Zimperium.
More info links on Android MMS Flaw & Stagefright
Android Media / Stagefright
Android Messaging MMS Security Flaw Fix
If you’re using Android Messaging app, instead of Google Android Hangouts, follow these steps…
Step 1 – Open Messaging app & Messaging Settings
Step 2 – Multimedia (MMS) Messages – Auto-retrieve OFF
Scroll down to Multimedia (MMS) Messages.
Uncheck Auto-retrieve. You’re done.
Matching SDK versions identified in build.gradle (Module: app) with the SDK versions you have installed via SDK Manager, then “Sync Now”, will fix most Android Studio build errors.
Common Android Studio build errors:
- Failed to Sync Gradle project
- Failed to find target android-21
- Install missing platform(s) and sync project
If you’re building / running someone else’s project that you’ve cloned from Github likely you’ll run into build errors in Android Studio.
Most Android Studio project build errors can be fixed in one file: /project/app/build.gradle
There are multiple Gradle build files, frustratingly named build.gradle. You want the build.gradle (Module: app) Gradle file.
Here’s a typical Gradle build.gradle file
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
compile fileTree(dir: 'libs', include: ['*.jar'])
Starting from the top of build.gradle file and moving down,
- This number should not be higher than the highest SDK version you have installed via SDK Manager. You can scroll through SDK Manager looking for SDK Platform entries, checking the API # (18 in the screenshot) and the Status – Installed:
- This line in your build.gradle should be set to the latest Android SDK build-tools version you have installed, not a revision/version that matches your target SDK. Again, the build tools version # is not related to your SDK version #. In general you want to install and use the latest build tools version.
- Visible in SDK Manager here:
- This should generally be the same as your compileSdkVersion
- After correcting version numbers in build.gradle, Android Studio will request you Sync with the following message:
- Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly. Sync Now.
- Click the blue Sync Now link to sync your project.
- After sync try building your project using Cmd + F9 (Control + F9 for Windows). Hopefully the Android Studio project builds without errors.
- If all goes well, you see a tiny completion message, bottom left corner saying: Gradle build finished in 2 sec.
- If things go wrong, the Messages window will pop-up showing the error
- Language Level Changed – Answer Yes