code

Google Play 서비스가 포함 된 Android 스튜디오

codestyles 2020. 8. 24. 08:22
반응형

Google Play 서비스가 포함 된 Android 스튜디오


새로운 Android Studio로 Google Play 서비스를 테스트하려고합니다. google_play_services.jar에 대한 종속성이있는 프로젝트가 있습니다. 그러나 프로젝트를 다시 빌드하려고하면 다음 오류가 발생합니다.

Information:[TstGP3-TstGP3] Crunching PNG Files in source dir: C:\Users\ans\AndroidStudioProjects\TstGP3\TstGP3\src\main\res
Information:[TstGP3-TstGP3] To destination dir: C:\Users\ans\AndroidStudioProjects\TstGP3\build\classes\res-cache\TstGP3-TstGP3
Information:Compilation completed with 2 errors and 0 warnings in 2 sec
Information:2 errors
Information:0 warnings
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\Android_BuildConfig_Generator\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\BuildConfig.java
    Error:Error:line (4)error: duplicate class: com.example.tstgp3.BuildConfig
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\aapt\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\R.java
    Error:Error:line (10)error: duplicate class: com.example.tstgp3.R

두 개의 BuildConfig 파일과 두 개의 R 클래스가있는 것 같습니다. 문제를 어떻게 해결할 수 있습니까?

편집하다:

컴파일러가 두 개의 R.java 파일을 컴파일하는 것을 확인했습니다. 하나는 내 프로젝트 폴더에 있고 다른 하나는 % USERPROFILE % .AndroidStudioPreview 폴더에 있습니다. 그래서 컴파일러 설정에서이 "Preview"폴더를 제외하려고했습니다. 이제 작동합니다. 이 문제는 프로젝트에서 Google Play 서비스 클래스를 사용하기 시작한 후에 만 ​​발생합니다. 누군가이 문제의 원인을 설명해 주시면 감사하겠습니다.


gradle 플러그인 v0.4.2의 출시 이후 Android 스튜디오에서 Google Play 서비스 설정이 간단하기 때문에 모든 답변이 잘못되었습니다. jar를 가져 오거나 프로젝트 라이브러리를 추가하거나 android studio 아래에 새 모듈을 추가 할 필요가 없습니다. 해야 할 일은 build.gradle 파일에 올바른 종속성을 추가하는 것입니다. 해당 링크를 살펴보십시오 : Gradle 플러그인 v0.4.2 업데이트 , 새 빌드 시스템이 샘플

이를 수행 하는 올바른 방법은 다음과 같습니다.

먼저 sdk 관리자실행하고 "extras"아래에있는 다음 파일을 다운로드하여 설치해야합니다 : Android 지원 저장소 , Google Play 서비스 , Google 저장소 .

android studio를 다시 시작하고 빌드 gradle 파일을 엽니 다. 종속성에서 다음과 같이 표시되도록 build.gradle 파일을 수정해야합니다.

dependencies {
    compile 'com.google.android.gms:play-services:6.5.87' 
 }

마지막으로 프로젝트를 동기화합니다 (AVD 관리자 왼쪽에있는 버튼).

6.5 버전부터는 전체 라이브러리 (매우 큰) 또는 필요한 모듈 만 포함 할 수 있습니다 (최상의 옵션). 즉, Google Maps 및 Analytics 만 필요한 경우 이전 예제를 다음 예제로 바꿀 수 있습니다.

dependencies {  
    compile 'com.google.android.gms:play-services-base:6.5.87'    
    compile 'com.google.android.gms:play-services-maps:6.5.87'  
}

여기 에서 전체 종속성 목록을 찾을 수 있습니다.

몇 가지 참고 사항 :

  • 최신 Play 서비스 라이브러리 버전을 사용하십시오. 이전 버전 인 경우 android studio에서 강조 표시합니다. 오늘 (2 월 5 일은 6.5.87) 현재 Gradle Please 에서 최신 버전을 확인할 수 있습니다.
  • Android Studio의 주요 업데이트 후 @ user123321의 의견에 제안 된대로 다음 지침에 따라 프로젝트를 다시 빌드합니다.

    프로젝트 폴더
    ./gradlew clean
    ./gradlew build로 cd하십시오.


  1. 파일-> 프로젝트 구조로 이동하십시오.
  2. '프로젝트 설정'을 선택하십시오.
  3. '종속성'탭을 선택하십시오.
  4. '+'를 클릭하고 '1. Library Dependencies'를 선택하십시오.
  5. 검색 : com.google.android.gms : play-services
  6. 최신 버전을 선택하고 '확인'을 클릭하십시오.

짜잔! Gradle과 싸울 필요가 없습니다. :)


EDITED: This guy really brought it home and has a good little tutorial http://instantiatorgratification.blogspot.com/2013/05/google-play-services-with-android-studio.html

one side note: I had played around so much that I needed to do a gradlew clean to get it to run succesfully

If you have imported your project or are working from the Sample Maps application located in \extras\google\google_play_services\samples\maps check out this tutorial.

https://stackoverflow.com/a/16598478/2414698

If you are creating a new project from scratch then note Xav's comments on that same post. He describes that Android Studio uses a different compiler and that you have to modify the build.gradle file manually. I did this with success. I copied

  • google-play-services.jar
  • google-play-services.jar.properties

into my lib directory and added the following to my build.gradle file

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/google-play-services.jar')
}

Also, if this is a new project check out this post, too.

https://stackoverflow.com/a/16671865/2414698


Most of these answers only address compile-time dependencies, but you'll find a host of NoClassDef exceptions at runtime. That's because you need more than the google-play-services.jar. It references resources that are part of the library project, and those are not included correctly if you only have the jar.

What worked best for me was to first get the project setup correctly in eclipse. Have your project structured so that it includes both your app and the library, as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup

Then export your app project from eclipse, and import into Android Studio as described here: http://developer.android.com/sdk/installing/migrate.html. Make sure to export both your app project and the google play services library project. When importing it will detect the library project and import it as a module. I just accepted all defaults during the project import process.


Google Play services Integration in Android studio.

Step 1:

SDK manager->Tools Update this

1.Google play services
2.Android Support Repository

Step 2:

chance in build.gradle 
defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:4.0.+'
}

Step 3:

 android.manifest.xml
<uses-sdk
        android:minSdkVersion="8" />

Step 4:

Sync project file with grandle.
wait for few minute.

Step 5:

File->Project Structure find error with red bulb images,click on go to add dependencies select your app module.
Save

Please put comment if you have require help. Happy coding.


None of the above solution worked for me. Not sure if it is specific to my setup or new release.

I am using Android Studio Beta 0.8.9 and I was not getting any com.google.android.gms:play-service in the library list on following this instruction:

Go to File -> Project Structure -> Select Project Settings -> Select 'Dependencies' Tab Click '+' -> 1.Library Dependencies -> Select com.google.android.gms:play-services:+

I had already done this:

First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.

What resolved it was to add from SDK Manager, "Google play services for Froyo" then repeating the first step.

Did not understand the reason properly but this worked.

PS: I just observed that even now when I search for play-services this does not come, but when I directly scroll and look through the list it is right there.


Follow this article -> http://developer.android.com/google/play-services/setup.html

You should to choose Using Android Studio

enter image description here

Example Gradle file:

Note: Open the build.gradle file inside your application module directory.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "{applicationId}"
        minSdkVersion 14
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.google.android.gms:play-services:6.1.+'
}

You can find latest version of Google Play Services here: https://developer.android.com/google/play-services/index.html


I've got this working after doing the following:

  • Have the google-play-services-lib as a module (note difference between module and project), then add the google-play-services.jar to your models "libs" directory.
  • After that add the jar to your build path through making a library or add the jar to another library. I generally have a single IDEA library which I add all my /libs/*.jar files to.
  • Add the library to your modules build path through Module Settings (F4).
  • Add the google-play-services-lib as a module dependency to your project.
  • Done!

Note: This doesn't give me the runtime exceptions either, it works.


Open your project build.gradle file and add below line under dependencies module.

dependencies {
    compile 'com.google.android.gms:play-services:7.0.0'
}

The below will be add Google Analytics and Maps if you don't want to integrate full library

dependencies {
    compile 'com.google.android.gms:play-services-analytics:7.0.0'
    compile 'com.google.android.gms:play-services-maps:7.0.0'
}

In my case google-play-services_lib are integrate as module (External Libs) for Google map & GCM in my project.

Now, these time require to implement Google Places Autocomplete API but problem is that's code are new and my libs are old so some class not found:

following these steps...

1> Update Google play service into SDK Manager

2> select new .jar file of google play service (Sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs) replace with old one

i got success...!!!


I copied the play libs files from the google-play-services_lib to my project libs directory:

  • google-play-services.jar
  • google-play-services.jar.properties.

Then selected them, right-click, "Add as libraries".

참고URL : https://stackoverflow.com/questions/16624827/android-studio-with-google-play-services

반응형