Ошибка реализации com.google.android.gms при запуске приложения в Android Studio - PullRequest
0 голосов
/ 14 октября 2018

Я получаю следующую ошибку при запуске приложения для Android:

Error: Program type already present: com.google.android.gms.common.api.zza

Ниже приведен файл модуля build.gradle:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 28
  buildToolsVersion '28.0.3'
  defaultConfig {
    applicationId 'com.example.photoeditor'
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    manifestPlaceholders = [appPackageName: "${applicationId}"]
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    pickFirst 'AndroidManifest.xml'
  }

  dexOptions {
    jumboMode true
  }

  productFlavors {}
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  implementation 'com.google.android.gms:play-services-ads:17.0.0'
  implementation 'com.adobe.creativesdk.foundation:auth:0.9.1251'
  implementation 'com.adobe.creativesdk:image:4.8.4'
  implementation 'com.localytics.android:library:4.0.1'
  testImplementation 'junit:junit:4.12'
}

Это проект build.gradleфайл ниже:

buildscript {
  repositories {
    jcenter()
    google()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'me.tatarka:gradle-retrolambda:3.6.1'
  }
}

allprojects {
  repositories {
    jcenter()
    google()
    mavenCentral()

    maven {
      url 'https://repo.adobe.com/nexus/content/repositories/releases/'
    }

    maven {
      url 'http://maven.localytics.com/public'
    }
  }
}

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

Это файл MainActivity.java ниже:

package com.example.photoeditor;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import com.adobe.creativesdk.aviary.AdobeImageIntent;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class MainActivity extends AppCompatActivity {
  private AdView mAdView;
  public static final String IMAGE_URI = "IMAGE_URI_KEY";

  private static final String TAG = "MainActivity";
  private static final int IMAGE_EDITOR_RESULT = 1;

  private ImageView mEditedImageView;

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

    mAdView = (AdView)findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    mEditedImageView = (ImageView) findViewById(R.id.edited_image_view);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      Uri imageUri = Uri.parse(getIntent().getExtras().getString(IMAGE_URI));
      Intent imageEditorIntent = new AdobeImageIntent.Builder(this).setData(imageUri).build();
      startActivityForResult(imageEditorIntent, IMAGE_EDITOR_RESULT);
      finish(); // Comment this out to receive edited image
    }
  }

  // Do something with the edited image
  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case IMAGE_EDITOR_RESULT:
          Uri editedImageUri = data.getParcelableExtra(AdobeImageIntent.EXTRA_OUTPUT_URI);
          Log.d(TAG, "editedImageUri: " + editedImageUri.toString());
          Bundle extra = data.getExtras();
          if (extra != null) {
            boolean changed = extra.getBoolean(AdobeImageIntent.EXTRA_OUT_BITMAP_CHANGED);
            Log.d(TAG, "Image edited: " + changed);
            if (changed) {
              mEditedImageView.setImageURI(editedImageUri);
            }
          }
          break;

        default:
          throw new IllegalArgumentException("Unexpected request code");
      }
    }
  }

  public static Intent getIntent(Context context, Bundle bundle) {
    Intent intent = new Intent(context, MainActivity.class);
    if (bundle != null) {
      intent.putExtras(bundle);
    }
    return intent;
  }
}

Это файл Activity_main.xml ниже:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    tools:context="com.example.photoeditor.MainActivity">

  <com.google.android.gms.ads.AdView
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      ads:adSize="BANNER"
      ads:adUnitId="@string/banner_id">
  </com.google.android.gms.ads.AdView>

  <ImageView
      android:id="@+id/edited_image_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:adjustViewBounds="true"
      android:contentDescription="@string/edited_image_content_desc"/>

</LinearLayout>

Я попытался добавитьразные версии для реализации gms gms и до сих пор не работали.Куда я иду не так?

Есть ли какой-нибудь другой файл, который нужно разместить здесь, чтобы найти решение?

Может кто-нибудь помочь, пожалуйста, как это исправить?

Заранее спасибо

Ответы [ 2 ]

0 голосов
/ 19 января 2019

Если вы используете Google Mobile Ads SDK версии 17. +, вам необходимо добавить метаданные
для объявлений в файле манифеста.

Подробнее см. https://developers.google.com/admob/android/quick-start.

0 голосов
/ 14 октября 2018

Попробуйте это

<com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

В коде Java

MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
mAdView.loadAd(adRequest);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...