0

I've recently started a new Android Studio project on one PC (very barebones: 3 Activitys, 1 Fragment, all very basic at this stage), and uploaded it to Version Control System through Android Studio (I assume it will only add the necessary files).

When I checkout the project on a different PC, Android Studio recognizes it is a project, and offers to open it as one. The gradle build completes, but on attempting to run the app on a device or emulator, I get the old problem:

Error: The number of method references in a .dex file cannot exceed 64K.

The only dependency as such is the 'bluealliance spectrum color picker', which I have used in the past without issue. I would assume that it has built something wrong, but considering everything is identical to the original project I can't see how it's going wrong - or how it could possibly have >64K methods.

Below are the gradle files:

mobile build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.aetherum.timetableapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url "http://github.com/wada811/Android-Material-Design-Colors/raw/master/repository/"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.thebluealliance:spectrum:0.6.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:preference-v7:23.2.1'
    compile 'com.android.support:preference-v14:23.2.1'
    compile 'com.wada811:android-material-design-colors:2.0.0'
}

And the project build.gradle :

buildscript {

    repositories {
        jcenter()
       maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I have tried cleaning and rebuilding the project, as well as checking it out again from git. At this stage, as an inexperienced developer, I'm out of ideas.

Sufian
  • 6,405
  • 16
  • 66
  • 120
nuggetbram
  • 345
  • 1
  • 12
  • You will have to convert your project to MultiDex. http://stackoverflow.com/questions/26609734/how-to-enable-multidexing-with-the-new-android-multidex-support-library – Augusto Carmo Aug 27 '16 at 15:55
  • Does clean build or disabling "instant run" work? These are the things which should fix most issues. :) – Sufian Aug 27 '16 at 15:58
  • @Sufian Instant run would have to be both my favourite and least favourite feature of android studio - I would be amazingly useful, but it seems to break everything (not in this case though) – nuggetbram Aug 27 '16 at 16:22

2 Answers2

3

The only dependency as such is the 'bluealliance spectrum color picker',

No, you have at least seven dependencies, not including any JARs that might be in libs/.

One of those dependencies is play-services. Unless you are using every single API in the Play Services SDK, you will be much better off using more granular dependencies (e.g., play-services-maps for Maps V2), to pull in only those bits of Play Services that you need.

BTW, you should change your 23.2.1 dependencies to 23.4.0, so all your Android Support Library dependencies are from the same version.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Oh my. Good catch. I guess this should be it. Lets see what the OP says. – Sufian Aug 27 '16 at 15:59
  • Changing to the specific gms service seemed to do the trick - but why would it work elsewhere without throwing the error? – nuggetbram Aug 27 '16 at 16:21
  • @nuggetbram: I can't explain that behavior. Particularly if you are starting from scratch in both places (e.g., you cleaned the project in the original location), you should get equivalent builds, as all of the tooling being used is specified, in the form of versions, in your project (e.g., both `build.gradle` files, `gradle-wrapper.properties`). – CommonsWare Aug 27 '16 at 16:38
0

Please remove this line of code

compile 'com.google.android.gms:play-services:9.4.0'
Pang
  • 9,564
  • 146
  • 81
  • 122
Ismaran Duwadi
  • 1,529
  • 12
  • 10