Android studio add aar

Как импортировать файл .aar в Android Studio 1.1.0 и использовать его в моем коде

Я прочитал много ответов, связанных с этой темой, но ни один из них не работал для решения моей проблемы, поэтому вам нужна помощь в этом:

Мне нужно импортировать файл .aar в проект, созданный с помощью Android Studio 1.1.0 , я импортировал его с помощью опции «Новый модуль», и на самом деле я не получаю никаких ошибок, я могу создать приложение и запустить его, но Когда я пытаюсь использовать класс из этого .aar-файла, Android Studio не находит ссылку на него, допустим, он не может распознать пакет, который я хочу включить в свой код.

Возможно, вы думаете, что я должен добавить зависимость, я уже это сделал, кажется, не работает.

Итак, кто-то может сказать мне, какой правильный способ импортировать и использовать файл .aar в Android Studio 1.1.0

Чтобы импортировать библиотеку .aar:

  1. Перейдите в меню «Файл»> «Создать»> «Новый модуль»
  2. Выберите «Импортировать пакет .JAR / .AAR» и нажмите «Далее».
  3. Введите путь к файлу .aar и нажмите «Готово».
  4. Перейдите в раздел «Файл»> «Структура проекта» (Ctrl + Shift + Alt + S).
  5. В разделе «Модули» в меню слева выберите «приложение».
  6. Перейдите на вкладку «Зависимости».
  7. Нажмите зеленый «+» в верхнем правом углу.
  8. Выберите «Dependency Module»
  9. Выберите новый модуль из списка.

Прочитав много ответов на Stackoverflow, я нашел решение для своей проблемы, я хочу, чтобы вы знали, какие шаги я выполнил, чтобы воспроизвести его:

  1. Добавьте файл .aar в папку lib.
  2. Используйте опцию «Новый модуль» в меню «Файл».
  3. Импортируйте файл .aar.
  4. Постройте град и скомпилируйте проект.

Когда я попытался использовать новый модуль в своем приложении, он не распознал класс внутри нового модуля.

Проблема связана с версией Gradle, я использовал 1.1.0, и в этой версии есть ошибка, поэтому мое предложение – изменить версию до 1.0.1 , есть проблема, уже открытая, чтобы исправить эту проблему https://code.google.com/p/android/issues/detail?id=162634

Вы должны изменить версию в файле build.gradle, расположенном в корне вашего проекта.

Дополнительную информацию об этой проблеме вы можете найти здесь: https://groups.google.com/forum/#!topic/adt-dev/1Ho_c8dALQQ

Думаю, в версии 1.2.0 эта проблема будет решена.

Источник

gpetuhov / android_add_jar_aar.txt

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Читайте также:  Beamng drive android 4pda
Add jar library in Android Studio:
1. Copy jar file into module’s libs folder
2. Right-click on it in Anroid Studio (in Project Files scope)
3. Choose Add as library
4. Make sure jar has been added as dependency in module’s build.gradle file
OR
Add jar or aar library:
1. File -> New -> New Module
2. Import JAR/AAR
3. List the library in top-level settings.gradle
include ‘:app’, ‘:my-library-module’
4. Add library to modules dependecies in module’s build.gradle
dependencies <
compile project(«:my-library-module»)
>
OR
Aar library can also be added like this:
1. Copy aar file into module’s libs folder
2. Add flatDir < dirs 'libs' >into top-level build.gradle like this:
allprojects <
repositories <
google()
jcenter()
flatDir <
dirs ‘libs’
>
>
>
3. Add compile(name:’name_of_the_file’, ext:’aar’) into dependencies section of module’s build.gradle file

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

How to add .aar dependency in library module?

I am having one .aar file of one library module.
I want to use it as a library or dependency in my other project’s library module.
How do I do it?

It works only if I add .aar reference in my project’s application module. But not working in library module.

5 Answers 5

Follow this setting and you will able to add .aar dependency to library module

build.gradle (Project: . )

build.gradle (Module: app)

build.gradle (Module: library_module)

settings.gradle (Project Settings)

In all modules (library or application) where you need the aar file you have to add in your build.gradle the repository:

and add the dependency:

You can use the top-level file to add the repositories, but you can’t add the dependencies in the top-level file.
Pay attention to the relative path of the libs folder that you are using in the module.

Sorry process involves 10 steps but these are super simple and easy.

1- New->Module

2- Select import .jar/aar package

3- Select your .aar file from location

4- We can see module is added but not configured with app module yet.

5- Go to Project Structure

6- Current project structure is like this one

7- Go to app module and press ‘+’ icon

8- Select 3rd option Module dependency

9- Select newly added .arr module

Читайте также:  Андроид календарь удалить только это событие

10- you can see the new module attached with app module. Now click apply.

you can see we are good to go.

I did it a bit differently than others have posted here.

My main goal was to create a library module that contained all the jar’s and aar’s that I would need. My main project would then depend on this library module — I only wanted a single line in the main project’s build.gradle to link this dependency.

Add a new library module to the project: File -> New -> New Module -> Android Library

within the library module, open the build.gradle and add:

now you can pop all the jar’s and aar’s into the /libs folder of your library module. Bonus: whatever the library name is doesn’t matter, it’s automatically discovered

Источник

How to Add and Use an AAR in AndroidStudio Project

I am trying to use a custom aar in my android project. I found dozens of examples in StackOverflow and the Web. Many failed at build, none worked. The clearest was at http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/
That came closest to working.

Here’s what I did

Successfully created a very simple AAR (Ref.aar) from Ref.java

Created a test project (RefTest)

Added reference to Ref.aar method (square) to onCreate in RefTest main activity.

Build->Clean then Build->Rebuild.
This produced error: cannot find symbol variable Ref

I’m sure I’m doing something naive or just plain dumb, but I can’t see it.
Any help appreciated.

2 Answers 2

1) create aar library and just put it in libs directory ( without «File->New->New Module->Import .JAR/.AAR Package» )

2) add to build.gradle (Module: app)

After that you can use Ref.square(int);

Your apk will contain after build:

When you import an AAR from built in helper tools using Import aar/jar option, studio creates a module with this aar.

So at this state you can see something similar to the state mentioned below. When display panel is Android,

Change your panel mode to Project and open your testaar , you can actually see a build.gradle file for your module and the corresponding aar.

That is why your statement

was not working.

To add this aar to your project(after using import aar/jar), what you can do is to first add the module to the settings.gradle (Project settings file)

then directly add to your application level build.gradle file

2)Another way is to

Right-click on your Application Module ->Select Open Module Settings -> Select the Module -> Go to Dependencies tab

Читайте также:  Статистика использования версий андроид 2021

P.S you can also open this window from Build->Edit Libraries and Dependencies

You will come across a window as below

Click on the small + icon, then Module option and finally add the required module(testaar)

Sync your code and voila it will start working now.

Источник

How to import a .aar file into Android Studio 1.1.0 and use it in my code

I have read a lot answers related to this topic, but none of them have worked to solve my problem, so need help with this:

I need to import a .aar file into a project created with Android Studio 1.1.0, I have imported it using the «New Module» option and actually I don’t receive any error, I can build the application and run it, but when I try to use a class from this .aar file Android Studio doesn´t find the reference to it, let’s say it can´t recognize the package that I want to include in my code.

You are maybe thinking that I must add the dependency, I have already done that, It seems to not work.

So someone could tell me which is the correct way to import and use a .aar file in Android Studio 1.1.0

4 Answers 4

To import an .aar library:

  1. Go to File>New>New Module
  2. Select «Import .JAR/.AAR Package» and click next.
  3. Enter the path to the .aar file and click finish.
  4. Go to File>Project Structure (Ctrl+Shift+Alt+S).
  5. Under «Modules,» in left menu, select «app.»
  6. Go to «Dependencies» tab.
  7. Click the green «+» in the upper right corner.
  8. Select «Module Dependency»
  9. Select the new module from the list.

After reading a lot of answers on Stackoverflow, I found the solution for my problem, I want you to know which were the steps I followed in order to reproduce it:

  1. Add a .aar file in my libs folder.
  2. Use «New Module» option under File menu.
  3. Import the .aar file.
  4. Build gradle and compile the project.

When I tried to use the new module in my app, It didn’t recognize any class inside the new module.

The problem is related to the version of Gradle, I was using 1.1.0 and there is a bug in this version, so my suggestion is to change the version to 1.0.1, there is an Issue already open in order to fix this problem https://code.google.com/p/android/issues/detail?id=162634

You should change the version in the build.gradle file located in the root of your project.

You can find additional information about this problem here https://groups.google.com/forum/#!topic/adt-dev/1Ho_c8dALQQ

I guess in version 1.2.0 this problem will be solved.

Источник

Оцените статью