2016-11-08 48 views
0

將Android Studio從2.2.1更新至2.2.2已完全破壞我的項目,因爲我無法訪問與Google地圖相關的任何內容。我的項目在更新之前運行良好,但現在沒有任何效果。在Google地圖活動中製作全新的項目也不起作用,併爲我提供完全相同的崩潰報告和結果。更新Android Studio打破Google地圖

我試過的東西: - 更新我所有的SDK,特別是與Google相關的SDK。 - 生成一個新的谷歌API密鑰 - 從頭開始​​創建 一個全新的項目 - 改變SupportMapFragment到MapFragment

錯誤,當我嘗試運行我的項目,我的手機上的全新地圖項目我得到(同樣的錯誤(所有其他gmaps應用我的手機上,所以我不認爲這是個問題)):

Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment 

我的build.gradle(從頭開始新的項目):

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 24 
buildToolsVersion "24.0.2" 
defaultConfig { 
    applicationId "com.example.simon.afinal" 
    minSdkVersion 19 
    targetSdkVersion 24 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
}) 
compile 'com.android.support:appcompat-v7:24.2.1' 
compile 'com.google.android.gms:play-services:9.8.0' 
testCompile 'junit:junit:4.12' 
} 

標準地圖活動:

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); 
} 


@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)); 
} 
} 

Gmaps XML版式文件:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.simon.afinal.MapsActivity" 
tools:layout="@layout/activity_maps" /> 

所有幫助深表感謝!

回答

0

時使用此獲得谷歌地圖

if (googleMap == null) { 

      googleMap = ((SupportMapFragment) getChildFragmentManager() 
        .findFragmentById(R.id.map)).getMap(); 

在XML映射的框架佈局像

<fragment 
       android:id="@+id/map" 
       class="com.google.android.gms.maps.SupportMapFragment" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

onMapReady方法篩選

@Override 
    public void onMapReady(GoogleMap googleMap) { 
     this.googleMap = googleMap; 


    } 
+0

給了我同樣的錯誤 –

0

你要導入的映射庫在gradle文件中是不同的。 更改您的依賴相應

編譯 'com.google.android.gms:發揮服務:9.8.0'

compile 'com.android.support:appcompat-v7:24.2.1' 
testCompile 'junit:junit:4.12' 
compile 'com.google.android.gms:play-services-maps:9.8.0' 

聲明類爲:

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback { 

或者是確定你的片段活動是v4包。

這應該工作一樣,都是基本的步驟獲得地圖

+0

FragmentActivity是definently V4,使用AppCombatActivity沒什麼區別,同樣的錯誤。 –

+0

和依賴關係呢?你改變了嗎? –

+0

是的,我改變了依賴關係,就像你在我爲了測試它而做的新活動中所要求的。從我以前完美工作的項目的依賴關係,依賴關係看起來像這樣:'compile'c​​om.google.android.gms:play-services-maps:9.8.0' compile'c​​om.google.android.gms:play -services-location:9.8.0' compile'c​​om.google.android.gms:play-services-plus:9.8.0' compile'c​​om.google.android.gms:play-services-base:9.8。0' compile'c​​om.google.android.gms:play-services-auth:9.8.0' compile'c​​om.google.android.gms:play-services-places:9.8.0'' –