0

I downloaded this git repository: https://github.com/jitsi/libjitsi

It contains two examples, but when I try to run them, the run button is disabled:

the app in android studio

When I select in the menu "Run" -> "Run", it tells me to add the edit configurations for the app and this window opens, but I don't know what to select there:

Run Menu -> add configuration

I found this additional site referring to the examples (when you scroll down a bit under examples and API): https://desktop.jitsi.org/Projects/LibJitsi

Boommeister
  • 1,591
  • 2
  • 15
  • 54

3 Answers3

3

Those are designed for use from the JVM, such as on a desktop or server. They contain main() methods for use with the java command. They are not Android apps and cannot be run from within Android Studio on Android devices.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Right, thank you... But I opened it now in IntelliJ but still can't run it? (p.s. I can only accept your answer in 5 minutes) – Boommeister Jun 04 '20 at 15:44
  • @GrgKro: "But I opened it now in IntelliJ but still can't run it?" -- there might be a recipe for running an arbitrary Java class in IDEA, but I am not an IDEA expert so I do not know what it is. Sorry! – CommonsWare Jun 04 '20 at 15:54
1

It seems that the project is not imported in a good way as in an Android Project and the reason for that is, It is not an Android Project It is just a basic java library.

If you want to add this functionality you can export the JAR and then add it as a library to your existing Android Project.

And if you want to clone some project from GitHub the better way could be: File -> New -> Project From Version Control -> Add the Git Repo Link

Prem Raval
  • 196
  • 2
  • 7
  • Thanks, I tried to add it as a library before, but that didn't work: I copied the full lib folder from the downloaded github folder and added it to my lib folder in my android studio project. Then I added `include ':libs:libjitsi'` to my settings.gradle file and tried to add `implementation ...`to my build gradle file, but just couldn't find out what I have to put there? – Boommeister Jun 04 '20 at 15:48
  • So the main requirement, what I figured out is that you want to add the GitHub repo as a dependency. The answer here : [ANSWER](https://stackoverflow.com/a/32682034/11611034) is great. Summary of steps is Add JitPack Repo, Add dependency, and you can also specify the latest commit to be taken – Prem Raval Jun 04 '20 at 16:10
  • Ok I was able to add the library to my project now, just in case some others have the same problem: I found another source for the library: https://download.jitsi.org/libjitsi/windows/libjitsi-1122-x64.zip. I unziped it and added the file libjitsi.jar to my `app` -> `libs` folder. Then in graddle.settings I put: `include ':libs:libjitsi'` and in `app` -> `build.gradle`: android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }} and `implementation files('libs\\libjitsi.jar')` as dependency. – Boommeister Jun 04 '20 at 16:11
1

It seems this is a library that is usually added as a dependency to another application. This library can however also be run as a standalone Java application. I'll leave to you whether that is the desired way to use this library, you can also consult the library documentation.

You can find how to run a Java application in IntelliJ IDEA in the documentation here:

https://www.jetbrains.com/help/idea/running-applications.html

https://www.jetbrains.com/help/idea/run-debug-configuration.html

I'll explain it my way.

To start a standalone Java application in IntelliJ IDEA, you need to "Run" the class with a public static void main(String[] args) function. In this project there are several, each with a different purpose. Use the project documentation and their JavaDoc to find out which one you want.

For this answer, I'll use org.jitsi.sctp4j.SampleClient which, according to its JavaDoc, is:

Sample SCTP client that uses UDP socket for transfers.

There are two ways to go about Running it. I'll start with the way I usually use.

Open the class in IDEA. You will see a green triangle next to the class name and also next to the main function. Both do the same thing.

Class and main() method

Click it and select "Run 'SampleClient.main()'" from the dropdown menu:

Run 'SampleClient.main()'

You can see the result at the bottom in the "Run" tab. That's it, at least for this class. The application should start successfully. You can stop it just like in Android Studio, using the red square either in the Run tab or at the top right in the navigation bar. Some applications will just perform an operation and stop on their own.

This class does not need any arguments for its main() method. If it needed them, we would have to add them in the Run Configuration...

And that is where we'll go for the second way to Run an application.

You will need this way if the main() method requires any arguments. You can also use it instead of opening the class file in the first place.

If you used the first method to start the application, you will see a Run Configuration already created for the SampleClient class. You can use it to run the application from the navigation bar, just like in Android Studio. You can also open the dropdown menu and select "Edit Configurations" to modify it or add a new Run Configuration:

Open Run Configurations

You can modify the configuration created for SampleClient - add program arguments, environment variables and more.

To create a new configuration, click the "+" icon and (in our case) select the "Application" type. Other types of Run Configurations include JUnit tests, Maven tasks, server deployments and more:

Add New Configuration

In the "Main class" field, either manually enter a qualified class name (code completion also works), or click the "..." on the right and select a class from the list of classes with main() methods:

Choose Main Class

You can again add program arguments and more. When you're done, you can use the configuration from the navigation bar.

MarvinCZ
  • 46
  • 6