private File nativeLibraryFromName(File nativeLibDirectory) throws MojoExecutionException {
    final File libraryFile;
    // Find the nativeArtifactFile in the nativeLibDirectory/ndkFinalLibraryName
    if (Const.ArtifactType.NATIVE_SYMBOL_OBJECT.equals(project.getPackaging())
        || Const.ArtifactType.NATIVE_IMPLEMENTATION_ARCHIVE.equals(project.getPackaging())) {
      libraryFile =
          new File(nativeLibDirectory, "lib" + ndkFinalLibraryName + "." + project.getPackaging());
    } else {
      final File staticLib = new File(nativeLibDirectory, "lib" + ndkFinalLibraryName + ".a");
      if (staticLib.exists()) {
        libraryFile = staticLib;
      } else {
        libraryFile = new File(nativeLibDirectory, "lib" + ndkFinalLibraryName + ".so");
      }
    }
    if (!libraryFile.exists()) {
      getLog()
          .error(
              "Could not locate final native library using the provided ndkFinalLibraryName "
                  + ndkFinalLibraryName
                  + " (tried "
                  + libraryFile.getAbsolutePath()
                  + ")");
      throw new MojoExecutionException(
          "Could not locate final native library using the provided ndkFinalLibraryName "
              + ndkFinalLibraryName
              + " (tried "
              + libraryFile.getAbsolutePath()
              + ")");
    }

    return libraryFile;
  }
 /**
  * Resolve the artifact type from the current project and the specified file. If the project
  * packaging is either 'a' or 'so' it will use the packaging, otherwise it checks the file for the
  * extension
  *
  * @param file The file being added as an artifact
  * @return The artifact type (so or a)
  */
 private String resolveArtifactType(File file) {
   if (Const.ArtifactType.NATIVE_SYMBOL_OBJECT.equals(project.getPackaging())
       || Const.ArtifactType.NATIVE_IMPLEMENTATION_ARCHIVE.equals(project.getPackaging())) {
     return project.getPackaging();
   } else {
     // At this point, the file (as found by our filtering previously will end with either 'so' or
     // 'a'
     return file.getName().endsWith(Const.ArtifactType.NATIVE_SYMBOL_OBJECT)
         ? Const.ArtifactType.NATIVE_SYMBOL_OBJECT
         : Const.ArtifactType.NATIVE_IMPLEMENTATION_ARCHIVE;
   }
 }
  private void cleanUp(
      File nativeLibDirectory,
      String ndkArchitecture,
      boolean libsDirectoryExists,
      File directoryToRemove,
      MakefileHelper.MakefileHolder makefileHolder,
      File makefileCaptureFile)
      throws IOException, MojoExecutionException {
    try {
      // Cleanup libs/armeabi directory if needed - this implies moving any native artifacts into
      // target/libs
      if (clearNativeArtifacts) {
        nativeLibDirectory =
            cleanUpNativeArtifacts(nativeLibDirectory, ndkArchitecture, libsDirectoryExists);
      }

      // Attempt to attach the native library if the project is defined as a "pure" native Android
      // library
      // (packaging is 'so' or 'a') or if the plugin has been configured to attach the native
      // library to the
      // build
      if (Const.ArtifactType.NATIVE_SYMBOL_OBJECT.equals(project.getPackaging())
          || Const.ArtifactType.NATIVE_IMPLEMENTATION_ARCHIVE.equals(project.getPackaging())
          || attachNativeArtifacts) {

        final File nativeArtifactFile;
        if (ndkFinalLibraryName == null) {
          nativeArtifactFile = findNativeLibrary(nativeLibDirectory);
        } else {
          nativeArtifactFile = nativeLibraryFromName(nativeLibDirectory);
        }

        final String artifactType = resolveArtifactType(nativeArtifactFile);
        if (nativeArtifactFile.getName().endsWith(".so") && !skipStripping) {
          getLog()
              .debug("Post processing (stripping) native compiled artifact: " + nativeArtifactFile);
          invokeNDKStripper(nativeArtifactFile);
        }

        getLog().debug("Adding native compiled artifact: " + nativeArtifactFile);

        File fileToAttach = nativeArtifactFile;
        if (!libsDirectoryExists && !clearNativeArtifacts) {
          final String destFileName =
              ndkArchitecture + File.separator + nativeArtifactFile.getName();
          final File destFile = new File(ndkOutputDirectory, destFileName);
          if (!destFile.equals(nativeArtifactFile)) {
            getLog().debug("Moving native compiled artifact to target directory for preservation");
            // This indicates the output directory was created by the build (us) and that we should
            // really
            // move it to the target (needed to preserve the attached artifact once install is
            // invoked)
            if (destFile.exists()) {
              destFile.delete();
            }
            getLog().debug(nativeArtifactFile + " -> " + destFile);
            FileUtils.moveFile(nativeArtifactFile, destFile);
            fileToAttach = destFile;
          } else {
            getLog()
                .debug(
                    "Not moving native compiled artifact "
                        + nativeArtifactFile
                        + " to target as they point to the same file");
            fileToAttach = nativeArtifactFile;
          }
        }

        String classifier = ndkArchitecture;
        if (ndkClassifier != null) {
          classifier += "-" + ndkClassifier;
        }

        projectHelper.attachArtifact(this.project, artifactType, classifier, fileToAttach);
      }

      // Process conditionally any of the headers to include into the header archive file
      processMakefileCapture(makefileCaptureFile, ndkArchitecture);

    } finally {
      // If we created any directories as part of the build, blow those away after we're done
      if (!libsDirectoryExists) {
        getLog().info("Cleaning up native library output directory after build");
        getLog().debug("Removing directory: " + directoryToRemove); // AJE - removes 'obj' directory
        FileUtils.deleteDirectory(directoryToRemove);
      }

      // If we created a makefile for the build we should be polite and remove any extracted include
      // directories after we're done
      if (makefileHolder != null) {
        getLog().info("Cleaning up extracted include directories used for build");
        MakefileHelper.cleanupAfterBuild(makefileHolder);
      }
    }
  }