简体   繁体   中英

Run e.g. calc.exe before build in IntelliJ with Android projects

I am trying to do some "stuff" before a build of my Android project.
The setup is roughly the following:

  • LibraryProject
  • AppA
  • AppB

I have run configurations for AppA + AppB
I know how to eg use the little checkmarks to eg

  • Deploy or not deploy
  • Run or not run

The one I am stuck with is Run Ant target .

What I want ( the reason for this question) is telling my current running application (most of the time it is AppA when I press "run", because I changed something in the code, to eg persist settings .

I have complete control over the app, and already wrote several scripts to eg talk via ADB to the device, or even talk to the current running app using UDP and a C# host application on my development machine. So if I am able to run a eg shutdown.exe (.NET written by me) I can tell my app to shutdown.

So to keep it "easy" I tried to get calc.exe to start when pressing "run" inside an Android project in Intellij. But I managed to get totally lost in the build.xml configuration IntelliJ uses for Android .

I tried:

  • adding an exec task to the build.xml
  • tell him to Run Ant targets
  • Adding some tests

They all have no effect. I can view the Ant Build in Intellij and start the task manually, still no effect (so I cant really know if they are started by the run configuration, because the may fail silently).

I added:

<target name="-pre-build">
    <exec executable="calc.exe"/>
    <echo message="HelloWorld"/>
</target>
<target name="-pre-compile">
       <exec executable="calc.exe"/>
        <echo message="HelloWorld"/>
</target>

Any tips what I am doing wrong? Oh, one more info. If I press the green button in the Ant Build toolbar on the highest level, android tells me something about "outdated build file", but I think this is ok. Seems like he tries to run the whole Ant file then, which imports some android tasks before - but this is not what I want anyway.

So can anyone provide me an example (to start calc.exe). I will figure the rest out and update the post if neccessary for others to help.

Chris

I came across this question when I was searching the same question in Google. Maybe it's quite late to post my answer, but better than none.

I found that you don't need a ant build script, that is just use the IntelliJ default system is just fine. For example, I am doing my project with android-ndk, so I want intelliJ run ndk-build NDK_DEBUG=1 -j4 before normal build.

Here is the solution:

  1. Run -> Editor configuration
  2. Select on of you build configuration in the left side of the dialog.
  3. On the right side there is an area marked as Before Launch
  4. Click the "plus" button, choose Run External Tool in the popup menu.
  5. Click the "plus" button in the new popup window
  6. Then you get into the real configuration window.

Sad thing is that I can't post image right now. You must want to see then on my blog

IDEA doesn't use any Ant build by default, what you see is probably the automatically generated build.xml for this project.

You can create a new build.xml file with just the following inside:

<project name="build" default="pre-build">
  <target name="pre-build">
    <exec executable="c:/windows/system32/calc.exe"/>
    <echo message="HelloWorld"/>
  </target>
</project>

In the Android Run/Debug configuration Before Launch section specify this Ant target to be run:

在发布之前运行ant

I've verified it with a small sample project and calc.exe gets properly executed before I run the Android configuration in IntelliJ IDEA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM