在构建apk relase

时间:2016-10-31 17:12:13

标签: android android-studio location google-places-api sha1

我正在编写第一个Android应用程序。我的应用程序包括firebase api,google map api,google geolocation api。他们有相同的api密钥。当我写app我在smarphone上测试它(sony experia Z1 android sdk 19)它运行良好。之后我将它构建到release-apk上,在google.console上发布了SHA版本,然后我将apk复制到3安卓智能手机,只有我测试的智能手机(索尼Z1)获得位置,2 orther智能手机(ss galaxy note 3 + ss galaxy edge 7)无法获得location.In索尼Z1,我已经unintall调试apk。除了位置之外,还有其他任何类似Firebase的地图。请帮我!这是我的gradle,manifest,google api manager。每个人都可以通过https://www.facebook.com/anhdatday

在线与我联系

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="le.orlando.ThinkSame">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="le.orlando.ThinkSame.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name="le.orlando.ThinkSame.MapsActivity"
            android:label="@string/title_activity_maps" />
        <activity android:name="le.orlando.ThinkSame.Main2Activity" />
        <activity android:name="le.orlando.ThinkSame.Main22Activity" />

        <!--
     ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
        -->

        <activity android:name="le.orlando.ThinkSame.Main4Activity"></activity>
    </application>

</manifest>

这是我的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
    applicationId "le.orlando.ThinkSame"
    minSdkVersion 17
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-places:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
}
apply plugin: 'com.google.gms.google-services'

这是我的主要活动java,它获得经度,纬度和城市名称,它在测试电话上运行良好。当我卸载调试版本然后复制release-apk和intall再次它仍然得到位置。但它不能在另外两部手机上运行。

package le.orlando.ThinkSame;

import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;

import java.util.List;

public class MainActivity extends AppCompatActivity implements
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    Button btn2,btnx,btnabout;
    EditText edtnn;

    GoogleApiClient mGoogleApiClient;
    Location mLastLocation;
    String city;
    double la, lo;
    Geocoder geocoder;
    List<Address> user = null;

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

        btn2 = (Button) findViewById(R.id.button2);
        btnx = (Button) findViewById(R.id.buttonX);
        btnabout =(Button) findViewById(R.id.buttonaboutme);
        edtnn = (EditText) findViewById(R.id.editTextNichName);

        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();
        }
        if (mGoogleApiClient != null) {
            mGoogleApiClient.connect();
        }

        SharedPreferences userDetails = getSharedPreferences("data", MODE_PRIVATE);
        String test1 = userDetails.getString("nickname", "");
        if (test1.equals("")) {
            Toast.makeText(MainActivity.this, "insert your Nickname", Toast.LENGTH_SHORT).show();
        } else {
            Intent mh2 = new Intent(MainActivity.this, Main2Activity.class);
            startActivity(mh2);
        }

        btnabout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent mhf = new Intent(MainActivity.this, Main4Activity.class);
                startActivity(mhf);
            }
        });

        btnx.setVisibility(View.GONE);
        edtnn.setGravity(Gravity.CENTER);
        edtnn.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            btnx.setVisibility(View.VISIBLE);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        btnx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                edtnn.getText().clear();
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!edtnn.getText().toString().equals("")) {

                    SharedPreferences userDetails = getSharedPreferences("data", MODE_PRIVATE);
                    SharedPreferences.Editor edit = userDetails.edit();
                    edit.clear();
                    edit.putString("nickname", edtnn.getText().toString().trim());
                    edit.putString("thanhpho", city);
                    edit.commit();

                    Intent mh2 = new Intent(MainActivity.this, Main2Activity.class);
                    startActivity(mh2);
                } else {
                    Toast.makeText(MainActivity.this, "Please insert your nickname !", Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (mLastLocation != null) {
            la = mLastLocation.getLatitude();
            lo = mLastLocation.getLongitude();
            geocoder = new Geocoder(MainActivity.this);
            try {
                user = geocoder.getFromLocation(la, lo, 1);
                city = user.get(0).getLocality();
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onConnectionSuspended(int i) {

    }
    @Override
    public void onConnectionFailed( ConnectionResult connectionResult) {
        try {
            // Start an Activity that tries to resolve the error
            connectionResult.startResolutionForResult(this, connectionResult.RESOLUTION_REQUIRED);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onBackPressed() {
    }


}

还有一件事,我的项目,当我找到重命名的方法时,我没有看到任何SHA在cl gra - - &gt;任务 - &GT; android - &gt; signingReport。这是问题吗?

enter image description here

这是我的谷歌API管理员

https://stackoverflow.com/questions/40295035/cant-get-location-on-app-release-apk

0 个答案:

没有答案