How to convert an existing Java Import class file into Android studio project

I need to know how to convert existing Java The class file is correctly added to the Android studio project My goal is to use these classes in Android projects

Class files have been written in eclipse for use in another java project

I have tried file - > New - > New Module - > select Java library - > finish, but this is not normal

As you probably know, the MyClass class is generated by default For testing, I imported com. Com into mainactivity example.* And try to build the object of this class in the oncreate () method

The problem is that it cannot compile the project I have the following errors:

Error:(7,1) error: package com.example does not exist
Error:(16,9) error: cannot find symbol class MyClass
Note: C:\Users\...\MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution Failed for task ':app:compileDebugJava'.
> Compilation Failed; see the compiler error output for details.

Anyone can explain how to import my java correctly Class files so that I can use them in my project?

Solution

You can add local library packages to your project in Android studio

>In the Android project window, right-click app and select new – > module. > In the create new module window, select Java library and click next Then give the module name, such as httpclient. In the library name field Then compare the java package name with the existing package com example. Same as XXX Then give an existing class file name anyfilename. > Now create a new module with the name httpclient, and the package name is com example. xxx. Use the empty class file anyfilename Java > now all Copy the java file to the httpclient folder created in the Android project Now it will also overwrite the empty file anyfilename java. > After copying, all Java files are automatically added to the library module. > You will get the module's third build Gradle file Your Android project may already have 2 builds Gradle's gone. > In the app's build The gradle file contains the dependency compilation project of the local library (": httpclient") Now you can import the java file in the httpclient module into the java file of the Android application

Note: the above information is based on Android studio 2.3 three

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>