RobolectricTestRunner class not found after SDK and Gradle upgrade












1















I upgraded recent legacy android application as follows,



CompileSDK 23 to 27
BuildTools 23.0.2 to 27.0.3
SupportLibVersion 23.0.2 to 27.1.1



below is my previous and current sourceset and test options code



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
robolectric {
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}


Current version with "robolectric" changed to "androidTest" and "testOptions" task added, otherwise it wont compile.



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
androidTest {
setRoot 'src/test/'
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}

testOptions {
unitTests {
includeAndroidResources = true
}
}


and this is how I integrated Robolectric



testImplementation 'org.robolectric:robolectric:3.3.2'


After making above changes, gradle sync succeeds, but Robolectric related classes are not recognized and could not be found.



I tried setting aapt2enabled as 'false', in this case gradle sync itself fails saying aapt2 is deprecated and will be removed in future. Please suggest me any solution.










share|improve this question


















  • 1





    org.robolectric:robolectric:3.8

    – IntelliJ Amiya
    Sep 20 '18 at 7:15











  • This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

    – Learner_Programmer
    Sep 20 '18 at 7:20
















1















I upgraded recent legacy android application as follows,



CompileSDK 23 to 27
BuildTools 23.0.2 to 27.0.3
SupportLibVersion 23.0.2 to 27.1.1



below is my previous and current sourceset and test options code



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
robolectric {
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}


Current version with "robolectric" changed to "androidTest" and "testOptions" task added, otherwise it wont compile.



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
androidTest {
setRoot 'src/test/'
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}

testOptions {
unitTests {
includeAndroidResources = true
}
}


and this is how I integrated Robolectric



testImplementation 'org.robolectric:robolectric:3.3.2'


After making above changes, gradle sync succeeds, but Robolectric related classes are not recognized and could not be found.



I tried setting aapt2enabled as 'false', in this case gradle sync itself fails saying aapt2 is deprecated and will be removed in future. Please suggest me any solution.










share|improve this question


















  • 1





    org.robolectric:robolectric:3.8

    – IntelliJ Amiya
    Sep 20 '18 at 7:15











  • This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

    – Learner_Programmer
    Sep 20 '18 at 7:20














1












1








1








I upgraded recent legacy android application as follows,



CompileSDK 23 to 27
BuildTools 23.0.2 to 27.0.3
SupportLibVersion 23.0.2 to 27.1.1



below is my previous and current sourceset and test options code



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
robolectric {
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}


Current version with "robolectric" changed to "androidTest" and "testOptions" task added, otherwise it wont compile.



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
androidTest {
setRoot 'src/test/'
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}

testOptions {
unitTests {
includeAndroidResources = true
}
}


and this is how I integrated Robolectric



testImplementation 'org.robolectric:robolectric:3.3.2'


After making above changes, gradle sync succeeds, but Robolectric related classes are not recognized and could not be found.



I tried setting aapt2enabled as 'false', in this case gradle sync itself fails saying aapt2 is deprecated and will be removed in future. Please suggest me any solution.










share|improve this question














I upgraded recent legacy android application as follows,



CompileSDK 23 to 27
BuildTools 23.0.2 to 27.0.3
SupportLibVersion 23.0.2 to 27.1.1



below is my previous and current sourceset and test options code



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
robolectric {
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}


Current version with "robolectric" changed to "androidTest" and "testOptions" task added, otherwise it wont compile.



sourceSets {

main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java']
}
androidTest {
setRoot 'src/test/'
java.srcDir file('src/test/java/')
resources.srcDir file('src/test/resources')
}
}

testOptions {
unitTests {
includeAndroidResources = true
}
}


and this is how I integrated Robolectric



testImplementation 'org.robolectric:robolectric:3.3.2'


After making above changes, gradle sync succeeds, but Robolectric related classes are not recognized and could not be found.



I tried setting aapt2enabled as 'false', in this case gradle sync itself fails saying aapt2 is deprecated and will be removed in future. Please suggest me any solution.







android android-gradle robolectric






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 20 '18 at 7:13









Learner_ProgrammerLearner_Programmer

4531625




4531625








  • 1





    org.robolectric:robolectric:3.8

    – IntelliJ Amiya
    Sep 20 '18 at 7:15











  • This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

    – Learner_Programmer
    Sep 20 '18 at 7:20














  • 1





    org.robolectric:robolectric:3.8

    – IntelliJ Amiya
    Sep 20 '18 at 7:15











  • This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

    – Learner_Programmer
    Sep 20 '18 at 7:20








1




1





org.robolectric:robolectric:3.8

– IntelliJ Amiya
Sep 20 '18 at 7:15





org.robolectric:robolectric:3.8

– IntelliJ Amiya
Sep 20 '18 at 7:15













This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

– Learner_Programmer
Sep 20 '18 at 7:20





This is a legacy application.Hence, kept the same version, however, tried version 3.8 too still same issue.Tried invalidating and restarting android studio as well.

– Learner_Programmer
Sep 20 '18 at 7:20












1 Answer
1






active

oldest

votes


















0














Your test class must not be in the "androidTest" directory but in the "Local unit test" directory (https://developer.android.com/studio/test/), i.e. "test" instead of "androidTest".



Because the "androidTest" directory is only for instrumented tests that run on a hardware device or emulator. And the advantage of Robolectric is that it does not need to run on a device or emulator. So you can either change "androidTest" to "test" in your gradle file or just remove the whole "androidTest {}" definition from your gradle file because src/test is the default path for the "Local unit test" directory.



I could fix the problem just by moving my test class from src/androidTest to src/test. But you will have to remove the "androidTest {}" definition from your gradle file, too.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52419557%2frobolectrictestrunner-class-not-found-after-sdk-and-gradle-upgrade%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your test class must not be in the "androidTest" directory but in the "Local unit test" directory (https://developer.android.com/studio/test/), i.e. "test" instead of "androidTest".



    Because the "androidTest" directory is only for instrumented tests that run on a hardware device or emulator. And the advantage of Robolectric is that it does not need to run on a device or emulator. So you can either change "androidTest" to "test" in your gradle file or just remove the whole "androidTest {}" definition from your gradle file because src/test is the default path for the "Local unit test" directory.



    I could fix the problem just by moving my test class from src/androidTest to src/test. But you will have to remove the "androidTest {}" definition from your gradle file, too.






    share|improve this answer




























      0














      Your test class must not be in the "androidTest" directory but in the "Local unit test" directory (https://developer.android.com/studio/test/), i.e. "test" instead of "androidTest".



      Because the "androidTest" directory is only for instrumented tests that run on a hardware device or emulator. And the advantage of Robolectric is that it does not need to run on a device or emulator. So you can either change "androidTest" to "test" in your gradle file or just remove the whole "androidTest {}" definition from your gradle file because src/test is the default path for the "Local unit test" directory.



      I could fix the problem just by moving my test class from src/androidTest to src/test. But you will have to remove the "androidTest {}" definition from your gradle file, too.






      share|improve this answer


























        0












        0








        0







        Your test class must not be in the "androidTest" directory but in the "Local unit test" directory (https://developer.android.com/studio/test/), i.e. "test" instead of "androidTest".



        Because the "androidTest" directory is only for instrumented tests that run on a hardware device or emulator. And the advantage of Robolectric is that it does not need to run on a device or emulator. So you can either change "androidTest" to "test" in your gradle file or just remove the whole "androidTest {}" definition from your gradle file because src/test is the default path for the "Local unit test" directory.



        I could fix the problem just by moving my test class from src/androidTest to src/test. But you will have to remove the "androidTest {}" definition from your gradle file, too.






        share|improve this answer













        Your test class must not be in the "androidTest" directory but in the "Local unit test" directory (https://developer.android.com/studio/test/), i.e. "test" instead of "androidTest".



        Because the "androidTest" directory is only for instrumented tests that run on a hardware device or emulator. And the advantage of Robolectric is that it does not need to run on a device or emulator. So you can either change "androidTest" to "test" in your gradle file or just remove the whole "androidTest {}" definition from your gradle file because src/test is the default path for the "Local unit test" directory.



        I could fix the problem just by moving my test class from src/androidTest to src/test. But you will have to remove the "androidTest {}" definition from your gradle file, too.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 10:03









        DominiqueDominique

        1,61111316




        1,61111316






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52419557%2frobolectrictestrunner-class-not-found-after-sdk-and-gradle-upgrade%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen