[英]Android Studio not generating APK
我有一個奇怪的問題,剛從現有的 Android Studio 2.3.3 項目開始。
構建過程不會自動生成 APK,在這種情況下 app-debug.apk 日志顯示構建成功,但項目目錄樹中的任何位置都沒有 APK。 但是,手動選擇 Build / Build APK 工作正常。
當我更改源並單擊運行時,這是一個問題。 構建過程成功,但隨后在模擬器中出現“錯誤安裝 APK”(因為 APK 不存在)。
這個問題只發生在一個項目上,我之前在玩 Espresso。 我的猜測是我在某處更改了設置,我只是不知道是哪一個。 我需要更改什么才能再次自動生成 APK? 包括 build.gradle。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 2
versionName "0.0.2"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("/home/user/keystore/keystore.jks")
storePassword "xxxxxxxxxxxxxxxxxx"
keyAlias "xxxxxxxxxxxxxxxxx"
keyPassword "xxxxxxxxxxxxxxxxxxx"
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.android.gms:play-services-location:10.2.4'
testCompile 'junit:junit:4.12'
}
由於Build.gradle
android studio 中的很多依賴,花費了太多時間然后說 Request time out。 所以看看Build.gradle
。 做這些步驟。
第一種方法:盡量減少依賴
第二種方法:為 androidX 添加 MultiDEX implementation 'androidx.multidex:multidex:2.0.1'
。
第三種方法:將類設為public class ApplicationDelegate extends MultiDexApplication { }
然后在 Application 標簽中像這樣添加 Android Manifest File
<application
android:name=".ApplicationDelegate"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
Hope it will solve your issue!
我的 Android Studio 一直這樣做,所以我想出了一個解決方法。 而不是去構建>構建APK。 我只是運行應用程序。
運行應用程序后,如果您轉到項目目錄中的 build > output > apk,您將在那里找到您的 APK。 當您運行應用程序時,Android Studio 很少會拋出錯誤。
編輯此 APK 在物理設備上不起作用我不知道是什么原因。 雖然它在模擬器上運行。
密鑰有問題,也許它不在路徑上......工作室不會報告任何內容(只是不構建捆綁包)。 單擊密鑰別名字段中的文件夾圖標,如果密鑰不在路徑上(最快檢查),則會出錯。
快樂編碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.