3

I am using two different flavors for two different architectures, because I have very large native libraries, and I want smaller binaries.

When I click on the "Run" icon, Android Studio ALWAYS builds and deploys the "Arm" flavor of our product. If I run this on an x86 emulator it fails because it doesn't have the libraries for x86.

Anybody know how to convince Android Studio to deploy the right version for a particular emulator?

Nick Palmer
  • 2,589
  • 1
  • 25
  • 34
  • I'm not sure what "I am using two different flavors for two different architectures, because I have very large native libraries, and I want smaller binaries" means. That tells me almost nothing, except that you are developing for two different architectures. When you setup a Run or Debug configuration, you need to select the target. Do you have the correct target selected? If you have it set to Run for an Arm target, there's no reason to expect it to build for x86. – iheanyi Oct 31 '14 at 21:48
  • You don't have to select a target when setting up a Run or Debug configuration. You can leave that as a "Prompt" setting to prompt you which device to run on. Additionally, setting the "Preferred" target to an x86 target still builds and installs the Arm version. – Nick Palmer Nov 03 '14 at 01:39
  • Hmm, have you looked at this: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-flavor-variants – iheanyi Nov 03 '14 at 16:28

2 Answers2

5

Try using the abiFilter property in your build.gradle.

This post explains how to use native libraries in different architectures:

In Chapter Building one APK per architecture, and doing it well! it says:

Use flavors to build one APK per architecture really easily, by using abiFilter property.

Try adding this to your gradle.build:

android{
  ...
  productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
        }
        mips {
            ndk {
                abiFilter "mips"
            }
        }
        armv7 {
            ndk {
                abiFilter "armeabi-v7a"
            }
        }
        arm {
            ndk {
                abiFilter "armeabi"
            }
        }
        fat
    }
}

You might just need the arm & x86.

After this, synchronize the project with the gradle file using

Tools > Android > Sync Project with Gradle Files

Now you should be able to switch between build variants and one APK by architecture should be generated.

Select Build Variants in the lower left corner. You should be able to switch between the different architectures in the Build Variant dropdown.

Hope this helps.

themenace
  • 2,601
  • 2
  • 20
  • 33
  • 1
    I already have that. That is how I am getting multiple APKs. What I want to know, is there a way to tell the Android Studio "Run" or "Debug" buttons which variant to build and deploy. – Nick Palmer Nov 03 '14 at 01:48
  • That is, how do you "switch between build variants" when hitting the "Run" button? – Nick Palmer Nov 03 '14 at 01:54
  • 2
    You're able to choose the different architectures / BuildVariants in the lower left corner. There's a BuildVariant view. Or have you already tried that? Just build the project and deploy it then on the device? – themenace Nov 03 '14 at 22:03
  • Thank you Dennis! That was the panel I was looking for! Can you post this as an "answer" so I can check it off? – Nick Palmer Nov 04 '14 at 01:10
0

First of all, there's now an easier way to distribute to different ABI's without using flavours - This is new to Android gradle 0.13.0 (2014/09/18) - http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits

There it says: Using the new Split mechanism, building a hdpi, and an mdpi version of the same app will share a lot of the tasks (like javac, dx, proguard). Additionally, it will be considered a single variant and the same test app will be used to test every multi-apk.

Maybe that will help you manage the tests easier

Sean
  • 5,176
  • 2
  • 34
  • 50
  • This is useful information for sure. I will consider revising my gradle build to take advantage of it, but I still think Android Studio will do the wrong thing here. I'll let you know when I get through the conversion to Split if that is the case. – Nick Palmer Nov 03 '14 at 01:41