将签名的 apk 从 android studio 部署到设备

Posted

技术标签:

【中文标题】将签名的 apk 从 android studio 部署到设备【英文标题】:Deploying signed apk from android studio to device 【发布时间】:2017-04-13 02:56:53 【问题描述】:

我正在尝试从 android studio 部署 signed apk。我已经使用所需的凭据配置了 build.gradle,但是当我尝试构建 .apk 时出现了一些警告。我尝试在 proguard 规则中添加一些命令,但仍然收到相同的警告。我该如何解决这个问题?

这是问题的图片。

这是 gradles 文件。

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.neenbedankt.android-apt'
//apply plugin: 'com.google.gms.google-services'
android 
    signingConfigs 
        release 
            keyAlias 'something'
            keyPassword 'something'
            storeFile file('D:/something')
            storePassword 'something'
        
    
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig 
        applicationId "com.aam.skillschool"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    
    buildTypes 
        release 
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        
    
    configurations.all 
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    


dependencies 
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
        exclude group: 'com.android.support', module: 'support-annotations'
    )
    compile 'com.google.apis:google-api-services-youtube:v3-rev179-1.22.0'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.jakewharton.timber:timber:4.3.1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.code.gson:gson:2.8.0'
    testCompile 'junit:junit:4.12'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    apt 'com.google.dagger:dagger-compiler:2.7'
    compile 'com.google.dagger:dagger:2.7'
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'br.com.mauker.materialsearchview:materialsearchview:1.2.0'
    compile 'com.google.http-client:google-http-client-android:+'
    compile 'com.google.api-client:google-api-client-android:+'
    compile 'com.google.api-client:google-api-client-gson:+'

提前致谢!

【问题讨论】:

您是否在任何地方使用“GoogleAuthUtil”?它现在已被弃用。同时使用useLibrary 'org.apache.http.legacy' 来摆脱http 问题。 我没有在任何地方使用 GoogleAuthUtil。我在哪里添加这个? 低于 buildToolsVersion "25.0.0" 就可以了 不,即使现在也没有帮助我得到同样的错误 嗯..似乎是一个proguard问题。也许你可以做这样的事情。***.com/questions/16931847/…或***.com/a/24109609/3111083 【参考方案1】:

你的导入库的非使用类已经被 proguard 删除了,恢复到你没有应用 pro-guard 的版本,那个版本应该可以工作。然后仔细包括你所有库的所有例外和规则在你的 pro-guard 规则中,然后尝试使用 proguard

【讨论】:

我已清空 pro-guard 并同步项目。除了Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android. 的一些警告之外,我没有收到任何错误,但是当我运行项目时,我得到与上述相同的错误 是的,因为 gradle 认为您包含的库实际上存在于您的构建中。但是当你构建时,它会寻找特定的类,并且由于 proguard 已经剥离了它们,它们再也找不到了。所以我认为你应该尝试我提出的建议。我遇到了和你一样的问题并以这种方式解决了它 Then carefully include all your exceptions and rules of all your libraries in your pro-guard rules and then try to use the proguard 我该怎么做?请在这里指导 访问您正在使用的所有库的页面,通常每个库开发人员都包含添加到他们库的 proguard 的说明 对我来说很奇怪,我可以手动从 build.gradle 中删除signingConfigs 并设置minifyEnable false 然后我生成签名的apk 然后android studio 生成签名的没有任何错误。只是一个与 httpclient 相关的警告

以上是关于将签名的 apk 从 android studio 部署到设备的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Android Studio 为 Flutter 构建签名的 apk

无法从 Android Studio 生成签名的 APK “任务 ':packageRelease' 执行失败”

如何在 android studio 中检索签名 APK 的密钥别名和密钥密码(从 Eclipse 迁移)

Android Studio 之签名

Android Studio:如何使用 Gradle 生成签名的 APK?

生成签名的 APK 不显示在 Android Studio 中