vpedak/droidtestrec

Clicking record deletes dependencies in my app's build.gradle

Closed this issue · 14 comments

I already have espresso setup and working in my AS2 project (using android gradle 2.0.0).

If I open up the recorder, select my app target and main activity, pressing record removes dependencies from my build.gradle and the app then fails to compile.

I also had such problem one time during testing. But it had never happen again, so I was unable to reproduce this.
I am using API that Android Studio has to modify build.gradle, I do not open the file directly. So it looks like something wrong happens in Studio and it clears the dependencies.
@biddster Can you please try it one more time? Is it reproducible in your environment?

I've tried it many times now. Every time I click record it deletes the entries from build.gradle.

I'm on a Mac, not sure if that's relevant.

@biddster I've create a fix and uploaded new version of plugin to the site - http://droidtestlab.com/AndroidTestsRecorder.zip. Can you please test it at your environment when you will have time? You should remove the plugin, download zip from site and install plugin from file (not from repository).

Thanks

Nope - same result I'm afraid, dependencies deleted.

@biddster I am very sorry that I am asking for this one more time, but since I can not reproduce this at my environment I can not check this myself.

I've created one more fix for this issue. New version of plugin is at the site again - http://droidtestlab.com/AndroidTestsRecorder.zip Can you please check it one more time?

Thanks a lot.

Oh don't apologise, happy to try and help debug. I'm afraid the deps still get deleted.
Here's what get's deleted:

screen shot 2016-04-15 at 09 34 18

Does the plugin really need to modify gradle files? I already have all the deps correct for espresso (I think).

Yes, I've to modify dependencies because I have to add my own jar to then. This jar contains all recording logic. I can not start recording without this.

But as I can see from your screenshot not all dependencies are deleted? Is this true? If not all dependencies are deleted this can be some specific problem. I saw one time that all dependencies are deleted in my case (and I hope that this is fixed with my last commit).

Understood. If I manually add the dependencies for the recorder, will it still try to modify the gradle file?

I've found the root cause (I was able to reproduce it with the same gradle build file as you have). Seems this is a bug in Android Studio. If you will take a look at "Event Log" after clicking Record button you should see error "NullPointerException: null". The reason is that Android Studio does not parse this line in gradle build:
compile project(path:":paymentstoolkit", configuration: project.properties["buildType"])

The problem is in this expression - project.properties["buildType"]. It looks like it is resolved to null and as result there is a NPE:

java.lang.NullPointerException
    at com.android.tools.idea.gradle.parser.GradleGroovyFile.convertValueToGroovySource(GradleGroovyFile.java:440)
    at com.android.tools.idea.gradle.parser.GradleGroovyFile.convertMapToGroovySource(GradleGroovyFile.java:416)
    at com.android.tools.idea.gradle.parser.Dependency.getGroovyElements(Dependency.java:152)
    at com.android.tools.idea.gradle.parser.BuildFileStatementFactory.setValues(BuildFileStatementFactory.java:36)
    at com.android.tools.idea.gradle.parser.BuildFileKey.setValue(BuildFileKey.java:264)
    at com.android.tools.idea.gradle.parser.GradleGroovyFile.setValueStatic(GradleGroovyFile.java:512)
    at com.android.tools.idea.gradle.parser.GradleBuildFile.setValue(GradleBuildFile.java:147)

Can you please remove configuration property and try it one more time? This should resolve the issue. I will submit a bug for Android Studio, but for now we will have to find a workaround

Just to make it clear. There are 2 components that are working with gradle build file. Gradle itself when it is building the project. And Android Studio that parse build file to find out dependencies and to show them in UI in Dependencies form.

Seems Gradle handle this situation and build is working fine. But when my plugin is asking for dependencies Androis Studio code is trying to parse them and fails. You can also open "Project Structure" dialog and switch to Dependencies tab and you will see "null" as configuration value.

I'll try it out without the expression. Unfortunately, that expression is to work around another gradle bug

Thanks for the continued assistance.

I've submitted the bug - https://code.google.com/p/android/issues/detail?id=207032 but I think it will not have a high priority and will not be fixed soon.

Can you provide a String value for configuration, for example hardcode it as "default" (without any project.properties) as a temporary solution?

Thanks for raising the bug, I've starred it.

I'll see what I can do about the gradle file. Not much, I think, without revisiting the android gradle bug and trying to find a different work around. If only goog would hurry up and fix it!

closing the issue since root cause is found and the only way now is to workaround this