7

早些時候我gradle這個是這樣的: 這是OFCOURSE不正確如何設置我的gradle這個最終版本的apk

apply plugin: 'android' 

android { 
    compileSdkVersion 19 
    buildToolsVersion '19.0.3' 

    defaultConfig { 
     minSdkVersion 11 
     targetSdkVersion 19 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      runProguard false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:gridlayout-v7:19.0.1' 
    compile 'com.android.support:appcompat-v7:+' 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:support-v4:+' 
    compile 'com.google.android.gms:play-services:+' 
    compile 'com.jakewharton:butterknife:4.0.+' 
    compile 'com.google.code.gson:gson:2.2.+' 
    compile 'com.google.android.gms:play-services:+' 
} 

所以在上傳我得到了來自谷歌的錯誤玩說,APK仍處於調試模式,並且不允許上傳該apk。

現在搜索結束後,我發現我需要改變我的gradle這個文件我終於想出了這個gradle這個:

請指引我,如果我是正確的!

apply plugin: 'android' 

android { 
    compileSdkVersion 19 
    buildToolsVersion '19.0.3' 

    defaultConfig { 
     minSdkVersion 11 
     targetSdkVersion 19 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      signingConfig signingConfigs.release 
     } 
    } 

    signingConfigs { 
     release { 
      storeFile file("F:\\MyAppFolder\\AppName.jks") 
      storePassword "abc1236" 
      keyAlias "prince" 
      keyPassword "abc1236" 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:gridlayout-v7:19.0.1' 
    compile 'com.android.support:appcompat-v7:+' 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:support-v4:+' 
    compile 'com.google.android.gms:play-services:+' 
    compile 'com.jakewharton:butterknife:4.0.+' 
    compile 'com.google.code.gson:gson:2.2.+' 
    compile 'com.google.android.gms:play-services:+' 
} 

現在我在哪裏出錯?

請幫忙。

+0

什麼是症狀?你是通過'./gradle assembleRelease'來請求發佈嗎?搜索堆棧溢出,比如'[android] gradle release',因爲有很多關於這個的問題。 – Jerry101

+2

確保你從'Build> Generate signed apk'生成已簽名的apk嗎? – pyus13

回答

37

在Studio窗口的左下方有一個名爲「Build Variants」的停靠視圖。

打開它並選擇發佈版本。

enter image description here

PS。您正在添加編譯'com.google.android.gms:play-services:+'兩次。

+0

如果「Build Variants」爲空,你會怎麼做? –

+0

@AndrewEbling - 您應該能夠定義一個:在Android Studio中右鍵單擊模塊,選擇模塊設置。在左側窗格中,選擇模塊(例如'app')。點擊Build Types標籤。 Build Variants就是在這裏定義的。點擊綠色的+按鈕來定義一個新的。 – CJBS

+0

按照這個答案http://stackoverflow.com/a/30953671/1488066 – AndroidLad

0

pyus13的評論是我會去的。

它說,在文檔(http://developer.android.com/tools/publishing/app-signing.html)在:

「注:包含密碼的build文件裏面你釋放鍵和密鑰存儲不是一個良好的安全習慣或者......有構建過程中的提示你爲這些密碼。「

因此,只需構建>生成已簽名的apk,Android Studio會提示您輸入密鑰庫/密碼並在發佈模式下生成apk。無需將密碼放入構建文件中。

相關問題