android 百度地图api 2.1.3版本申请key(SDK 4.0)

本文介绍了Android平台定位SDK v4.0版本引入的Key验证体系,包括Key机制的作用、申请配置步骤以及如何验证Key的有效性等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Key机制说明

为了给用户提供更优质的服务,Android平台定位 SDK自v4.0版本开始引用了Key验证体系。因此,当您选择使用v4.0及之后版本的定位SDK时,需要先申请且配置Key,并在程序相应位置填写您的Key。(选择使用v3.3及之前版本SDK的开发者,不需要使用Key)

Key机制:每个Key仅且唯一对于1个应用验证有效,即对该Key配置环节中使用的包名匹配的应用有效。因此,多个应用【包括多个包名】需申请多个Key,或者对1个Key进行多次配置。

LBS开放平台所有产品均使用统一Key机制,用户只需通过配置便能获得不同API/SDK产品服务,且Key“一一对应”机制,不仅保证您的应用所享有的服务资源(如服务配额,服务次数等)安全性和专属性,或选择启动关闭部分API/SDK服务,同时随着LBS开放平台的发展,未来您还可通过Key获得VIP服务(如提升服务次数、定制化服务等)。

说明:若你需要在同一个工程中同时使用定位SDK和地图SDK,可以共用同一个key

2. 申请配置Key步骤

Key的申请地址为:http://lbsyun.baidu.com/apiconsole/key

申请与配置步骤详见如下:

2.1 登录百度账号

访问API控制台页面,若您未登录百度账号,请先登录。

2.2 进入API控制台

登录会跳转到API控制台服务,具体如下图:

2.3 创建密钥(access key)

点击“创建密钥”,系统将为您自动生成密钥,如下图所示:

2.4 配置密钥
2.4.1 打开“配置”密钥对话框

选中新生成密钥,点击右侧栏的“配置”按钮

将弹出如下对话框:

2.4.2 选择密钥属性

选择“Key type”为“for mobile”,如下图所示:

2.4.3 输入“安全码”

安全码的组成规则为:Android签名证书的sha1值+“;”+packagename(即:数字签名+分号+包名)

注意:中间的分号为英文状态下的分号!

1. 获取shal值

您可以通过两种方法来获取Android签名证书的sha1值:(需事先配置好Android环境))

第一种方法:使用keytool

第1步:运行进入控制台

第2步:定位到.android文件夹下,输入cd.android

第3步,输入keytool -list -v -keystore debug.keystore,会得到三种指纹证书,选取SHA1类型的证书(密钥口令默认是android,如果有修改请填写修改后的值)

其中keytool为jdk自带工具;keystorefile为Android 签名证书文件

第二种方法:在adt 22中直接查看

如果使用adt 22,可以在eclipse中直接查看:winows -> preferance -> android -> build。如下图示:其中“SHA1 fingerprint”值即为Android签名证书的sha1值。

2. 获取包名

包名是Android应用程序本身在AndroidManifest.xml 中定义的名称,例如:

2.4.4 完成配置

完成密钥配置点击“确定”完成Key的配置工作,请妥善保管您所申请的Key。至此,您可以将配置完成的Key添加至您的应用程序里,进行程序开发了。

配置完成后,KEY后面的状态会变为“已配置”。

2.5 Key有效性验证

用户申请Key的有效性可以通过获取error code来判断,如果error code返回是166,则表示key无效,需要用户重新确认key的有效性。


官网申请说明地址:http://developer.baidu.com/map/geosdk-android-key.htm#key2.4

plugins { id &#39;com.android.application&#39; } apply from: &#39;jacoco-report.gradle&#39; def cfg = rootProject.ext.configuration android { compileSdk cfg.targetSdk defaultConfig { applicationId cfg.applicationId minSdk cfg.minSdk targetSdk cfg.targetSdk versionCode cfg.versionCode versionName cfg.versionName } signingConfigs { release { storeFile file("$rootDir/platform.jks") storePassword = "123456" keyPassword = "123456" keyAlias = "ktplatfrom" } debug { storeFile file("$rootDir/platform.jks") storePassword = "123456" keyPassword = "123456" keyAlias = "ktplatfrom" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39; } debugCoverage { minifyEnabled false testCoverageEnabled false } } // buildTypes { // release { // minifyEnabled false // signingConfig signingConfigs.release // } // debug { // minifyEnabled false // signingConfig signingConfigs.debug // debuggable true // testCoverageEnabled false // } // } applicationVariants.all { variant -> variant.outputs.all { output -> def newName = "ktLauncher.apk" outputFileName = newName } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } dataBinding { enabled = true } buildFeatures { aidl true } //儿童模式 flavorDimensions "default" productFlavors { _NORMAL_MODE { buildConfigField("int", "user_model", "0") } _CHILD_MODE { buildConfigField("int", "user_model", &#39;1&#39;) } } testOptions { unitTests { includeAndroidResources = true returnDefaultValues = true } } } gradle.projectsEvaluated { tasks.withType(JavaCompile) { Set<File> fileSet = options.bootstrapClasspath.getFiles() List<File> newFileList = new ArrayList<>(); //将framework.jar插入到最前面 newFileList.add(new File("libs/framework.jar")) //最后将原始的数据插入 newFileList.addAll(fileSet) options.bootstrapClasspath = files( newFileList.toArray() ) } } dependencies { // api fileTree(include: [&#39;*.jar&#39;], dir: &#39;libs&#39;) implementation rootProject.ext.dependencies["appcompat"] implementation rootProject.ext.dependencies["material"] implementation rootProject.ext.dependencies["constraintlayout"] implementation rootProject.ext.dependencies["lifecycle-extensions"] implementation rootProject.ext.dependencies["gson"] implementation project(&#39;:base&#39;) compileOnly files(&#39;libs/framework.jar&#39;) implementation &#39;com.github.bumptech.glide:glide:4.12.0&#39; implementation &#39;com.android.support:design:28.0.0&#39; implementation "androidx.constraintlayout:constraintlayout:2.1.3" annotationProcessor &#39;com.github.bumptech.glide:compiler:4.12.0&#39; // test testImplementation &#39;org.powermock:powermock-module-junit4:2.0.7&#39; testImplementation &#39;org.powermock:powermock-module-junit4-rule:1.7.4&#39; testImplementation &#39;org.powermock:powermock-api-mockito2:2.0.7&#39; testImplementation &#39;org.mockito:mockito-core:3.3.3&#39; testImplementation &#39;android.arch.core:core-testing:1.1.1&#39; testImplementation &#39;org.mockito:mockito-inline:3.11.2&#39; } -----build.gradle----------- apply plugin: &#39;jacoco&#39; //gradlew clean & gradlew createOfflineTestCoverageReport & gradlew jacocoTestReport tasks.withType(Test) { jacoco.includeNoLocationClasses = true jacoco.excludes = [&#39;jdk.internal.*&#39;] } configurations { jacocoAnt jacocoRuntime } jacoco { toolVersion = "0.8.5" } def offline_instrumented_outputDir = "$buildDir.path/intermediates/classes-instrumented/debugCoverage" tasks.withType(Test) { jacoco.includeNoLocationClasses = true jacoco.excludes = [&#39;jdk.internal.*&#39;] } def coverageSourceDirs = [ &#39;src/main/java&#39; ] task jacocoTestReport(type: JacocoReport, dependsOn: "test") { group = "Reporting" description = "Generate Jacoco coverage reports" classDirectories.from = fileTree( dir: &#39;./build/intermediates/javac/debugCoverage/classes/&#39;, excludes: [ &#39;**/R.class&#39;, &#39;**/R$*.class&#39;, &#39;**/Manifest*.*&#39;, &#39;**/*Test*.*&#39;, &#39;android/**/*.*&#39;, &#39;**/BuildConfig.*&#39;, &#39;**/**Bean.class&#39;, &#39;**/inputmethod/*&#39;, &#39;**/config/*.*&#39;, &#39;**/flex/*.*&#39;, &#39;**/AssetsUtils.class&#39; ] ) getSourceDirectories().setFrom(files(coverageSourceDirs)) getExecutionData().setFrom(files(&#39;./build/jacoco/testDebugUnitTest.exec&#39;)) } jacocoTestReport { reports { xml.enabled true html.enabled true html.destination file("build/test-results/jacocoHtml") } } /* This task is used to create offline instrumentation of classes for on-the-fly instrumentation coverage tool like Jacoco. See jacoco classId * and Offline Instrumentation from the jacoco site for more info. * * In this case, some classes mocked using PowerMock were reported as 0% coverage on jacoco & Sonarqube. The issue between PowerMock and jacoco * is well documented, and a possible solution is offline Instrumentation (not so well documented for gradle). * * In a nutshell, this task: * - Pre-instruments the original *.class files * - Puts the instrumented classes path at the beginning of the task&#39;s classpath (for report purposes) * - Runs test & generates a new exec file based on the pre-instrumented classes -- as opposed to on-the-fly instrumented class files generated by jacoco. * * It is currently not implemented to run prior to any other existing tasks (like test, jacocoTestReport, etc...), therefore, it should be called * explicitly if Offline Instrumentation report is needed. * * Usage: gradle clean & gradle createOfflineInstrTestCoverageReport & gradle jacocoTestReport * - gradle clean //To prevent influence from any previous task execution * - gradle createOfflineInstrTestCoverageReport //To generate *.exec file from offline instrumented class * - gradle jacocoTestReport //To generate html report from newly created *.exec task */ task createOfflineTestCoverageReport(dependsOn: [&#39;instrument&#39;, &#39;testDebugCoverageUnitTest&#39;]) { group = "reporting" doLast { ant.taskdef(name: &#39;report&#39;, classname: &#39;org.jacoco.ant.ReportTask&#39;, classpath: configur3+ations.jacocoAnt.asPath) ant.report() { executiondata { ant.file(file: "$buildDir.path/jacoco/testDebugCoverageUnitTest.exec") } structure(name: &#39;Example&#39;) { classfiles { fileset(dir: "$project.buildDir/intermediates/javac/debugCoverage") } sourcefiles { fileset(dir: &#39;src/main/java&#39;) } } //Uncomment if we want the task to generate jacoco html reports. However, the current script does not exclude files. //An alternative is to used jacocoTestReport after this task finishes //html(destdir: "$buildDir.path/reports/jacocoHtml") } } } createOfflineTestCoverageReport.dependsOn(clean) /* * Part of the Offline Instrumentation process is to add the jacoco runtime to the class path along with the path of the instrumented files. */ gradle.taskGraph.whenReady { graph -> if (graph.hasTask(instrument)) { tasks.withType(Test) { doFirst { systemProperty &#39;jacoco-agent.destfile&#39;, buildDir.path + &#39;/jacoco/testDebugCoverageUnitTest.exec&#39; classpath = files(offline_instrumented_outputDir) + classpath + configurations.jacocoRuntime } } } } /* * Instruments the classes per se */ task instrument(dependsOn:&#39;compileDebugUnitTestSources&#39;) { doLast { println &#39;Instrumenting classes&#39; ant.taskdef(name: &#39;instrument&#39;, classname: &#39;org.jacoco.ant.InstrumentTask&#39;, classpath: configurations.jacocoAnt.asPath) ant.instrument(destdir: offline_instrumented_outputDir) { fileset(dir: "$buildDir.path/intermediates/javac/debugCoverage") } } } -----jacoco-report.gradle--------------- jacoco-report.gradle 在同一个项目中的base模块可以正常生成jacoco单元测试覆盖率报告,但是在app模块无法生成,build文件夹中,都没有jacoco和 test-results文件夹。上述的jacoco-report.gradle和build.gradle是app模块的内容 请问应该如何解决app模块无法显示jacoco报告的问题i
最新发布
07-23
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值