Running the Java Main method in Android studio

Source: Internet
Author: User
Tags jcenter

First, running the Java Main method in studio is theoretically feasible, after all, with the JDK in studio.
If you can't run the main method, it's definitely not the right place to do it.

I started building Javalib's moudle to create Java classes, and ran the following error:

Error:gradle:a problem occurred configuring root project ' Newtest '.
> could not resolve all files for configuration ': Classpath '.
   > Could not download Kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.1.3-2) ...

> could not download Protobuf-java.jar (com.google.protobuf:protobuf-java:3.0.0)
      > could don't get Resource ' Https://jcenter.bintray.com/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar ' ...
.
.... There's dozens of more lines of code in the back.

I did a direct check on the Internet: studio to run the main method, but not a few, and finally asked colleagues, in order to succeed.

The correct approach is:
1. Create a javalib moudle in the Android workspace.
Configure the Build.gradle for the entire project, and note that this is not a single moudle build.gradle
is to add a URL to the central warehouse of the workspace.

   Jcenter () {
            url ' http://jcenter.bintray.com/'
        }

I have only jcenter (), not add that website, No. Just add this to it.

Complete Configuration Code:

Top-level build file where your can add configuration options common to all sub-projects/modules.

Buildscript {

    repositories {
        Google ()

    //Focus
        Jcenter () {
            url "http://jcenter.bintray.com/"

        }
    }
    dependencies {
        classpath ' com.android.tools.build:gradle:3.0.1 '


        //Note:do not place your application dependencies here; They belong
        //In the individual module build.gradle files
    }

allprojects {
    repositories { C19/>google ()
        jcenter ()
    }

task Clean (type:delete) {
    Delete rootproject.builddir
}

To create a Java class directly in an Android project running the main method is definitely not the case, above I said in the Lib project this method I was successful in the trial.
Some people may be building a Lib project directly, you can run the main method, possibly the default configuration of the workspace.
After all, everyone's configuration environment is likely to be different, if not enough to try other people's approach, someone must have encountered the same situation as you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.