Android Build.Gradle file edit

Good Morning every one, 

I develop a plugin for android studio target code edition. in one part of the work I need to edit and add some features to the build.gradle file. is there any API that I can take a look at in order to understand how can I reach this goal? 

thank you in advance

0

Hi,
Sorry for late reply.
Working with build.gradle files is same as any other groovy file. Please take a look at this document for basic information on working with text: https://www.jetbrains.org/intellij/sdk/docs/tutorials/editor_basics/working_with_text.html

0
Avatar
Permanently deleted user

Hi Nikita, I tried another way to edit the gradle file programmatically from my plugin, but it seems that it didn't write anything. my code looks like the following:

GradleBuildModel model = GradleBuildModel.get(myProject);
DependenciesModel dependenciesModel = model.dependencies();
dependenciesModel.addArtifact(IMPLEMENTATION, "com.squareup.okio:okio:1.14.1");
WriteCommandAction.runWriteCommandAction(myProject, () -> {model.applyChanges();});


do you have any idea that what is the issue? 

thanks in advance

0
Avatar
Permanently deleted user

I understand the problem is the fact that I got the wrong build.gradle file, I need the build.gradle (Module:app), do you have any idea about how can I get that object?

0
Avatar
Permanently deleted user

I change the first line of the code, and the problem has been solved. 

0

Glad to see you have the problem solved!

0

请先登录再写评论。