Android studio references aar for java development

How to use the aar package in android studio for java development, such as libs/libyuv-release.aar

In Android Studio, you can add  .aar files to your project by following these steps:

  1. Place  .aar the file into the project  libs directory. If you don't have a directory in your project  libs , you can create one.

  2. In your project's root  build.gradle file, make sure your  allprojects section includes  libs the directory as a repository:

    allprojects {
        repositories {
            ...
            flatDir {
                dirs 'libs'
            }
        }
    }
    
  3. In your module's (usually  appbuild.gradle file, add  .aar the file as a dependency:

    dependencies {
        ...
        implementation(name: 'libyuv-release', ext: 'aar')
    }
    

    where  name is the name of your  .aar file (not including  .aar the extension) and ext is the file extension.

  4. Sync your Gradle project. In Android Studio's toolbar, click the "Sync Project with Gradle Files" button, or select "File > Sync Project with Gradle Files" from the menu.

.aar Now you should be able to use the classes in the file in your project  . If you encounter "unable to resolve symbol" errors when using these classes, you may need to import these classes. In a Java file, you can use  import statements to import  .aar classes in the file. For example, if you want to use  com.android.libyuv.Yuv2Rgb classes, you can add the following import statement to your Java file:

import com.android.libyuv.Yuv2Rgb;

Then, you can use the class in your code  Yuv2Rgb .

Guess you like

Origin blog.csdn.net/jacke121/article/details/132892945