Julio Garcia
Julio Garcia

Reputation: 1954

Force Android Studio to compile ARM64 versions of external libraries

I am trying to embed CrossWalk on native android using the method explained here: embed crosswalk in android studio

The problem that I am having is that android studio is not building the needed libraries for ARM64, even though those libraries are on the Maven repository.

Here is my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
    }
    flatDir{
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'org.xwalk:xwalk_core_library:22.52.561.4'
    compile (name: 'wikitudesdk', ext:'aar')
    testCompile 'junit:junit:4.12'
}

Is there a way to tell android studio expicitly to compile those libraries?

Upvotes: 1

Views: 4659

Answers (2)

Julio Garcia
Julio Garcia

Reputation: 1954

OK I finally found the solution here: diego.org

Basically if you need the ARM64 library you first need to download the correct library yourself:

curl -O https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/22.52.561.4/xwalk_core_library-22.52.561.4-arm64.aar

Then install it to the local maven repository:

mvn install:install-file -DgroupId=org.xwalk -DartifactId=xwalk_core_library \
  -Dversion=22.52.561.4-arm64 -Dpackaging=aar  \
  -Dfile=xwalk_core_library-22.52.561.4-arm64.aar \
  -DgeneratePom=true

And update you build gradle so that the repositories point to you local maven repo:

repositories {
    mavenLocal()
}

and you compile the correct lib:

compile 'org.xwalk:xwalk_core_library:22.52.561.4-arm64'

Hope it helps someone as future reference.

Upvotes: 3

nandsito
nandsito

Reputation: 3852

Take a look at section Crosswalk AAR Version in https://crosswalk-project.org/documentation/android/embedding_crosswalk/crosswalk_aar.html:

  1. Support different CPU architectures with each APK (such as for ARM, x86).

    A product flavor defines a customized version of the application build by the project. We can have different flavors which generate apk for each architecture.

    android {
      ...
      productFlavors {
        armv7 {
          ndk {
            abiFilters "armeabi-v7a", ""
          }
        }
        x86 {
          ndk {
            abiFilters "x86", ""
          }
        }
      }
    }
    

    Get the version code from the manifest. Add an extra digit to the end of the version code which implicity specifies the architecture. The x86 final digit is 4, arm is 2.

    versionCode manifest.versionCode + 4
    
  2. Build your project with Gradle, the following commands will build the corresponding arch apk in build/apk directory.

    $ gradle assemblex86
    $ gradle assemblearmv7
    

    Use $ gradle build to build both arm and x86 APKs at once.

OpenCV uses these magic strings for arm64: digit 3 and abiFilter arm64-v8a (reference).

Upvotes: 2

Related Questions