#StackBounty: #android #intellij-idea #android-source #android-studio-3.0 Developing AOSP with Android Studio 3.1 Cannot build test apk…

Bounty: 200

I am trying to build a customized AOSP (on Android M, api 23) using Android Studio because I want to run instrumented tests on custom apps running on the hardware. This is on ubuntu 64. It is very frustrating for me as there is no clear cut path.

I ran the script

~/myAOSP/development/tools/idegen/intellij-gen.sh myApp company/apps/MY_APP

and opened MY_APP.iml in Android Studio.

Now I am trying to build the apk using gradle just for my project, and also the test apk.

The main myAOSP uses makefiles.

I am trying to build, but it cannot find junit-4.12

I put the jars into the local libs folder via a soft link

ln -s  ../../../prebuilts/devtools/tools/lib libs

which definitely has junit-4.12.jar

Failed to resolve: junit:junit:4.12

I followed the instructions here and also used the build.gradle as a template https://developer.android.com/studio/intro/migrate#migrate-intellij

// This buildscript{} block configures the code driving the build
buildscript {
    * The nested repositories{} block declares that this build uses the
    * jcenter repository.
    repositories {

    * This block declares a dependency on the 3.1.0 version
    * of the Gradle plugin for the buildscript.
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'

 * This line applies the com.android.application plugin. Note that you should
 * only apply the com.android.application plugin. Applying the Java plugin as
 * well will result in a build error.
apply plugin: 'com.android.application'

 * This dependencies block includes any dependencies for the project itself. The
 * following line includes all the JAR files in the libs directory.
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    // Add other library dependencies here (see the next step)
    androidTestImplementation 'com.android.support.test:runner:1.0.2'

 * The android{} block configures all of the parameters for the Android build.
 * You must provide a value for at least the compilation target.
android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    * This nested sourceSets block points the source code directories to the
    * existing folders in the project, instead of using the default new
    * organization.
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']

        // Move the tests to tests/java, tests/res, etc...

        * Move the build types to build-types/<type>
        * For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        * This moves them out of them default location under src/<type>/... which would
        * conflict with src/ being used by the main source set.
        * Adding new build types or product flavors should be accompanied
        * by a similar customization.

repositories {

I saw posts like Developing AOSP with Android Studio but they are out of date or not relevant.
Also http://ronubo.blogspot.com/2016/01/debugging-aosp-platform-code-with.html?view=magazine and Error:(23, 17) Failed to resolve: junit:junit:4.12

I am looking for a working solution to the problem of building an instrumented test apk for an app in customized AOSP, and running instrumented tests on it, in Android Studio 3.1 (or later).

a) if it is possible to build the instrumented test apk in gradle AS 3.1 (or later), then please suggest a fix to the gradle error shown.

b) if gradle build in a) above is NOT possible, then do I need to build instrumented test apk using the current makefiles in the customized AOSP?

c) if I build the instrumented test apk using makefiles, then can I still use the instrumentation UI in AS to run the tests on the hardware?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.