找不到方法compile()

编程入门 行业动态 更新时间:2024-10-27 20:25:41
本文介绍了找不到方法compile()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在android studio中添加一个lib,但无法正常工作.这是屏幕截图

我也试图在gradle.build中添加一个依赖项,但这也行不通.也许是因为我落后于代理人了?

解决方案

您使用了错误的 build.gradle 文件.

您不能在顶级文件中使用 compile .使用 module/build.gradle .

< PROJECT_ROOT> \ app \ build.gradle 是特定于应用程序模块的.

< PROJECT_ROOT> \ build.gradle 是顶级构建文件" ,您可以在其中添加所有子项目/模块共有的配置选项./p>

此外,您还应该将库包含在 dependencies 块中,而不是在 buildscript 块中.

顶级文件示例:

buildscript {储存库{jcenter()}依赖项{classpath'com.android.tools.build:gradle:2.3.0'classpath'com.google.gms:google-services:3.0.0'}}

在 app \ build.gradle 中,您仅定义模块的属性:

apply插件:"com.android.application"安卓 {compileSdkVersion ...buildToolsVersion ...}依赖项{//..... 这里 !}

I want to add a lib in android studio but it is not working. Here is a screenshot

I also tried to add a dependency in the gradle.build but that also does not work. Maybe it is because I am behind a proxy ?

解决方案

You are using the wrong build.gradle file.

You can't use compile in the top-level file. Use the module/build.gradle.

<PROJECT_ROOT>\app\build.gradle is specific for app module.

<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.

Also you should include the libraries in the dependencies block, not inside the buildscript block.

Top level file example:

buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.google.gms:google-services:3.0.0' } }

In the app\build.gradle you define only the properties for the module:

apply plugin: 'com.android.application' android { compileSdkVersion ... buildToolsVersion ... } dependencies { //..... HERE ! }

更多推荐

找不到方法compile()

本文发布于:2023-11-14 05:02:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   方法   compile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!