Skip to content

Latest commit

 

History

History
 
 

prefab

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Prefab Samples

The samples in this directory demonstrate how to create and consume C/C++ dependencies with the Android Gradle Plugin. Dependencies are packaged within AARs using the Prefab package format. The Android Gradle Plugin natively supports producing and consuming these, so you do not need to worry about the details of the packaging format.

The individual samples will explain in more detail, but the typical workflow for a consumer of a native dependency is:

  1. Enable the prefab build feature in your build.gradle file.
  2. Add the dependency to the dependencies block of your build.gradle file.
  3. Import the package in your CMakeLists.txt or Android.mk file.
  4. Link the dependencies to your libraries.

Linking the dependency to your library will automatically make the headers available, link the required libraries, and include the dependencies you use in your application or library.

To produce an AAR that exposes C/C++ APIs:

  1. Enable the prefabPublishing build feature in your build.gradle file.
  2. Use android.prefab in your build.gradle file to declare the names of the libraries you wish to export and the headers that define their interface.

To test your packages, follow the steps for package consumers. Note that until https://issuetracker.google.com/120166563 is fixed it is not possible to depend on the native components of an AAR generated by another module of the same project when using Android Studio. Instead, test in a separate project. You can import the AAR into your test project either directly or by publishing it to a Maven repository.

With that in mind, the samples here collectively demonstrate prefab usage:

  • prefab-publishing shows how to create an AAR for distributing native libraries
  • prefab-dependency shows how to import native dependencies from GMaven
  • curl-ssl: for shows to use 2 very specific and important AARs (curl and ssl)

Prefab Availability

Support for Prefab packages has been available Android Gradle Plugin since version 4.0:

  • Consuming native dependencies requires AGP 4.0+
  • Generating AARs that export native dependencies requires AGP 4.1+

The AARs used by the samples here are hosted at Google Maven, but you can host your AARs anywhere accessible to gradle.

Pre-requisites

Please check for the individial sample's README.md for anything specific to that sample.

Support

If you've found an error in these samples, please file an issue.

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.

License

Copyright 2020 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.