Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Mensagem de erro ao carregar app: File cannot excedd 64k.

Mensagem de erro ao carregar app: File cannot excedd 64k.

//Mensagm de erro:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2411Library
:app:prepareComAndroidSupportAppcompatV72411Library
:app:prepareComAndroidSupportCardviewV72411Library
:app:prepareComAndroidSupportMediarouterV72300Library
:app:prepareComAndroidSupportSupportV42411Library
:app:prepareComAndroidSupportSupportVectorDrawable2411Library
:app:prepareComGoogleAndroidGmsPlayServices940Library
:app:prepareComGoogleAndroidGmsPlayServicesAds940Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite940Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics940Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl940Library
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing940Library
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite940Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth940Library
:app:prepareComGoogleAndroidGmsPlayServicesAuthBase940Library
:app:prepareComGoogleAndroidGmsPlayServicesBase940Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement940Library
:app:prepareComGoogleAndroidGmsPlayServicesCast940Library
:app:prepareComGoogleAndroidGmsPlayServicesCastFramework940Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut940Library
:app:prepareComGoogleAndroidGmsPlayServicesContextmanager940Library
:app:prepareComGoogleAndroidGmsPlayServicesDrive940Library
:app:prepareComGoogleAndroidGmsPlayServicesFitness940Library
:app:prepareComGoogleAndroidGmsPlayServicesGames940Library
:app:prepareComGoogleAndroidGmsPlayServicesGass940Library
:app:prepareComGoogleAndroidGmsPlayServicesGcm940Library
:app:prepareComGoogleAndroidGmsPlayServicesIdentity940Library
:app:prepareComGoogleAndroidGmsPlayServicesIid940Library
:app:prepareComGoogleAndroidGmsPlayServicesLocation940Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps940Library
:app:prepareComGoogleAndroidGmsPlayServicesNearby940Library
:app:prepareComGoogleAndroidGmsPlayServicesPanorama940Library
:app:prepareComGoogleAndroidGmsPlayServicesPlaces940Library
:app:prepareComGoogleAndroidGmsPlayServicesPlus940Library
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet940Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanager940Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi940Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks940Library
:app:prepareComGoogleAndroidGmsPlayServicesVision940Library
:app:prepareComGoogleAndroidGmsPlayServicesWallet940Library
:app:prepareComGoogleAndroidGmsPlayServicesWearable940Library
:app:prepareComGoogleFirebaseFirebaseAnalytics940Library
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl940Library
:app:prepareComGoogleFirebaseFirebaseAuth940Library
:app:prepareComGoogleFirebaseFirebaseAuthCommon940Library
:app:prepareComGoogleFirebaseFirebaseAuthModule940Library
:app:prepareComGoogleFirebaseFirebaseCommon940Library
:app:prepareComGoogleFirebaseFirebaseConfig940Library
:app:prepareComGoogleFirebaseFirebaseCrash940Library
:app:prepareComGoogleFirebaseFirebaseDatabase940Library
:app:prepareComGoogleFirebaseFirebaseDatabaseConnection940Library
:app:prepareComGoogleFirebaseFirebaseIid940Library
:app:prepareComGoogleFirebaseFirebaseMessaging940Library
:app:prepareComGoogleFirebaseFirebaseStorage940Library
:app:prepareComGoogleFirebaseFirebaseStorageCommon940Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug
:app:transformClassesWithInstantRunVerifierForDebug
:app:transformClassesWithJavaResourcesVerifierForDebug
:app:mergeDebugJniLibFolders
:app:transformNative_libsWithMergeJniLibsForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor
:app:generateDebugInstantRunAppInfo
:app:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 5 mins 21.766 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console


//Menu_lista_alunos


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="br.com.rodrigo.agendinha.ListaAlunosActivity">
    <item
        android:id="@+id/menu_enviar_notas"
        android:title="Enviar notas"
        android:icon="@mipmap/ic_enviar"
        app:showAsAction="always" />
    <item
        android:id="@+id/menu_baixar_provas"
        android:title="Baixar provas"
        android:icon="@mipmap/ic_download"
        app:showAsAction="always"/>

    <item
        android:id="@+id/menu_mapa"
        android:title="Visualizar mapa"
        android:icon="@mipmap/ic_mapa"
        android:showAsAction="always"/>




</menu>


//Maps Activity.java

package br.com.rodrigo.agendinha;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}


//ListaAlunos.Activity

package br.com.rodrigo.agendinha;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.Browser;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import br.com.rodrigo.agendinha.adapter.AlunosAdapter;
import br.com.rodrigo.agendinha.converter.AlunoConverter;
import br.com.rodrigo.agendinha.dao.AlunoDAO;
import br.com.rodrigo.agendinha.modelo.Aluno;

public class ListaAlunosActivity extends AppCompatActivity {

    private ListView listaAlunos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista_alunos);

        listaAlunos = (ListView) findViewById(R.id.lista_alunos);

        listaAlunos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> lista, View item, int i, long l) {
                Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(i);
                Intent intentVaiProFormulario = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
                intentVaiProFormulario.putExtra("aluno", aluno);
                startActivity(intentVaiProFormulario);
            }
        });

        Button novoAluno = (Button) findViewById(R.id.novo_aluno);
        novoAluno.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentVaiProFormulario = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
                startActivity(intentVaiProFormulario);
            }
        });

        registerForContextMenu(listaAlunos);
    }

    private void carregaLista() {
        AlunoDAO dao = new AlunoDAO(this);
        List<Aluno> alunos = dao.buscaAlunos();
        dao.close();


        AlunosAdapter adapter = new AlunosAdapter(this, alunos);
        listaAlunos.setAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        carregaLista();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_lista_alunos, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_enviar_notas:
                new EnviaAlunosTask(this).execute();
                break;
            case R.id.menu_baixar_provas:
                Intent vaiParaProvas = new Intent(this, ProvasActivity.class);
                startActivity(vaiParaProvas);
                break;
            case R.id.menu_mapa:
                Intent vaiParaMapa = new Intent(this, MapsActivity.class);
                startActivity(vaiParaMapa);
                break;


        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) {

        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        final Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);

        MenuItem itemLigar = menu.add("Ligar");
        itemLigar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                if (ActivityCompat.checkSelfPermission(ListaAlunosActivity.this, Manifest.permission.CALL_PHONE)
                        != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(ListaAlunosActivity.this,
                            new String[]{Manifest.permission.CALL_PHONE}, 123);
                } else {
                    Intent intentLigar = new Intent(Intent.ACTION_CALL);
                    intentLigar.setData(Uri.parse("tel:" + aluno.getTelefone()));
                    startActivity(intentLigar);
            }
                return false;
            }
        });

        MenuItem itemSMS = menu.add("Enviar SMS");
        Intent intentSMS = new Intent(Intent.ACTION_VIEW);
        intentSMS.setData(Uri.parse("sms:" + aluno.getTelefone()));
        itemSMS.setIntent(intentSMS);

        MenuItem itemMapa = menu.add("Visualizar no mapa");
        Intent intentMapa = new Intent(Intent.ACTION_VIEW);
        intentMapa.setData(Uri.parse("geo:0,0?q=" + aluno.getEndereco() ));
        itemMapa.setIntent(intentMapa);

        MenuItem itemSite = menu.add("Visitar site");
        Intent intentSite = new Intent(Intent.ACTION_VIEW);

        String site = aluno.getSite();
        if (!site.startsWith("http://")){
            site = "http://" + site;
        }

        intentSite.setData(Uri.parse(site));
        itemSite.setIntent(intentSite);

        MenuItem deletar = menu.add("Deletar");
        deletar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {

                AlunoDAO dao = new AlunoDAO(ListaAlunosActivity.this);
                dao.deleta(aluno);
                dao.close();

                carregaLista();
                return false;
            }
        });
    }
}
2 respostas
solução!

Olá LeAnna,

No Android existe um limite máximo para o número de métodos que podem existir no seu APK. Esse limite é de 65536 e ele é facilmente esgotado quando usamos muitas bibliotecas externas em nossos aplicativos.

Quando isso acontece, devemos configurar o build do nosso projeto para que ele separe a aplicação em múltiplos arquivos .dex. Para isso, edite o arquivo build.gradle e adicione as linha indicadas abaixo:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...

        // Adicione a linha abaixo para ativar o build multiDex
        multiDexEnabled true
    }
    ...
}

dependencies {
  // Adicione a linha abaixo para incluir a biblioteca multiDex
  compile 'com.android.support:multidex:1.0.0'
}

Depois você precisa fazer algumas alterações no arquivo AndroidManifest.xml, adicionar o package na tag manifest e o atributo android:name na tag application como abaixo:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

Para entender um pouco melhor esse problema e suas possíveis soluções, recomendo a página da documentação oficial:

https://developer.android.com/studio/build/multidex.html

Obrigada Jeferson! Agora deu certo =)