LoginSignup
27

More than 5 years have passed since last update.

Android Studioでアプリのバージョン情報はmanifestには書かない

Posted at

問題

EclipseからAndroid Studioに移行してから初めて、アプリのバージョンアップを行いました。
それまでの経験で、以下のように、manifestファイルにバージョン情報を埋め込んだのですが、出来上がったapkをストアにアップロードしようとすると、バージョンが上がっていない旨のエラーが出てしまう。

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.package.name"
      android:versionCode="2"
      android:versionName="1.1">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        ...
    </application>
</manifest>

解決策

少しだけ不思議になったが、Android Studioがきちんと該当行に警告を出してくれている。
それによると、バージョン情報はgradle側に設定しなければならないらしい。

↓これの build.gradle (Module: app)
スクリーンショット 2016-01-22 15.15.24.png

上記build.gradleの中にversionCodeversionNameを設定する部分があるので、その部分を変更すれば、アプリのバージョン情報を書き換えられる。

build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "io.ironoir.----"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}

教訓

IDEの警告にはきちんと耳を傾けよう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27