【发布时间】:2018-07-29 13:22:07
【问题描述】:
更新
忘了说这是一个 xamarin 编码。
以防万一:
我将 android 选项中的链接选项从无更改为仅 sdk 程序集
我还启用了 proguard
我在位置请求方面遇到问题,但仅在发布的 apk 中,它总是说应用程序已停止。我尝试调试它并找到发生异常的部分。我的应用程序在调试模式下运行良好,所以我不知道为什么它在发布的 apk 测试期间遇到异常。使用 Asus zenfone 3 Nougat 和 OPPO lollipop 测试,结果相同(发布失败,调试没有问题)。
这是我的部分代码
public void m4_setUpAllClickable()
{
try
{
btnEnableGPS.Click += delegate
{
enableGPSLocation();
};
}
catch { throw; }
}
private async void enableGPSLocation()
{
try
{
GoogleApiClient
googleApiClient = new GoogleApiClient.Builder(this)
.AddApi(LocationServices.API)
.Build();
googleApiClient.Connect();
LocationRequest
locationRequest = LocationRequest.Create()
.SetPriority(LocationRequest.PriorityHighAccuracy)
.SetSmallestDisplacement(LocationValues.minimunDisplacement)
.SetInterval(LocationValues.normalInterval)
.SetFastestInterval(LocationValues.fastestInterval);
LocationSettingsRequest.Builder
locationSettingsRequestBuilder = new LocationSettingsRequest.Builder()
.AddLocationRequest(locationRequest);
locationSettingsRequestBuilder.SetAlwaysShow(false);
//****** -> Problem Occur in this part and I don't know why since it is going straight to app has stopped instead of catch exception
LocationSettingsResult
locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync(
googleApiClient, locationSettingsRequestBuilder.Build());
//****** -> ends here
if (locationSettingsResult.Status.StatusCode == CommonStatusCodes.ResolutionRequired)
{
locationSettingsResult.Status.StartResolutionForResult(this, 1);
}
else if (locationSettingsResult.Status.StatusCode == CommonStatusCodes.Success)
{
if (activitySource == "GPS Failed")
{
Intent intent;
intent = new Intent(this, typeof(Activity_AssignedList));
StartActivity(intent);
FinishAffinity();
}
else if (activitySource == "GPS Disabled")
{
Finish();
}
}
}
catch { throw; }
}
【问题讨论】:
-
异常是什么?
-
1) 查看
logcat输出以确定原因 2) 您是否为发布版本打开了链接器?如果是,请将其关闭并重新测试,因为它可能是未找到的类/方法异常(查看logcat确定) -
@SushHangover,您的意思是关于链接器是仅使用链接选项 sdk 程序集的 android 选项设置吗?我还启用了我的 proguard,以防万一
-
@jace “可能性”是否与所需的 Linker 和/或 Proguard 剥离类/方法有关,您需要查看 logcat 输出以确定这一点。
-
@SushiHangover 感谢您的帮助。我会看看是不是因为proguard和linker。明天我会更新我对 logcat 的问题。我现在只需要出去工作。
标签: android xamarin xamarin.android android-gps