简体   繁体   English

Android开发中的新手; 如何将Java库添加到Android Studio项目?

[英]Very new at Android development; how do I add a Java lib to Android Studio project?

I faked my way into the screen below with some ease in Android Studio. 我在Android Studio中轻松伪造了进入以下屏幕的方式。 I had no intention of trying to make the app DO anything; 我无意尝试使该应用程序执行任何操作; just a first step toward an actual working model (which I have for Windows). 只是迈向实际工作模型的第一步(对于Windows,这是我必须具备的)。 Took several hours--one reason: managed to screw up first attempt so that I couldn't make gradle happy [much time spent here] and had/chose to start over. 花了几个小时-一个原因:设法搞砸了第一次尝试,以使我不能让gradle开心[花很多时间在这里],不得不重新开始。 I don't want to do that again, so I'm being cautious since I'm on shaky newbie ground. 我不想再做一次,因此我处于谨慎状态,因为我处在摇摇欲坠的新手领域。

在此处输入图片说明

I added the non-GUI part of my working Netbeans app with no problem. 我毫无问题地添加了工作的Netbeans应用程序的非GUI部分。

I copied the method below from my working project in Netbeans. 我从Netbeans的工作项目中复制了以下方法。 I know that I don't need this module to compile, since the Android GUI mechanism is so different: 我知道我不需要编译此模块,因为Android GUI机制是如此不同:

private static void onClickShow(ActionEvent e) {

    int rowsShown;
    ArrayList<String> comb = null;
...
}

But suppose I did need to import that class from java.awt.event . 但是假设我确实需要java.awt.event 导入该类

Sooner or later I'm going to have to include a java library for some reason. 出于某种原因,迟早我将不得不包含一个Java库。 Yes? 是? (If not, I guess I've asked a bad question!) (如果没有,我想我问了一个坏问题!)

Just to see if I could import, I got myself to the screen below by clicking File | Project Structure 为了查看是否可以导入,我通过单击“ File | Project Structure我”进入了以下屏幕File | Project Structure File | Project Structure and adding C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar (which is where Netbeans told me I'd find java.awt.event). File | Project Structure并添加C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar (这是Netbeans告诉我的java.awt.event)。

在此处输入图片说明

I thought I'd better hold off doing anything else until I get this question answered: 我以为我最好不做任何其他事情,直到我回答这个问题:

IS the highlighted bottom line above HOW TO ADD A JAVA LIBRARY to an Android Studio project? 如何将Java库添加到Android Studio项目上方的突出显示的底线是吗?

(I've Googled and read but little applies to Android Studio, so I'm at my own mercy at interpreting and I need other eyes to help ensure I don't screw up this project since gradle is involved again.) (我已经使用Google搜索和阅读过,但对Android Studio几乎没有什么了解,因此我对翻译的理解不由自主,我需要其他眼睛来帮助确保我不会搞砸这个项目,因为gradle再次涉及到。)

You have to put dependencies in your build.gradle file 您必须将依赖项放入build.gradle文件中

dependencies {
compile "your jar location"

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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