diff --git a/lib/android_apk.rb b/lib/android_apk.rb index 022f84f..3b54a7f 100644 --- a/lib/android_apk.rb +++ b/lib/android_apk.rb @@ -79,7 +79,11 @@ class AndroidApk # @return [String] Return a file path of this apk file attr_accessor :filepath - NOT_ALLOW_DUPLICATE_TAG_NAMES = %w(application).freeze + NOT_ALLOW_DUPLICATE_TAG_NAMES = %w( + application + sdkVersion + targetSdkVersion + ).freeze DPI_TO_NAME_MAP = { 120 => "ldpi", @@ -104,7 +108,7 @@ class AndroidManifestValidateError < StandardError # Do analyze the given apk file. Analyzed apk does not mean *valid*. # # @param [String] filepath a filepath of an apk to be analyzed - # @raise [AndroidManifestValidateError] if AndroidManifest.xml has multiple application tags. + # @raise [AndroidManifestValidateError] if AndroidManifest.xml has multiple application, sdkVersion tags. # @return [AndroidApk, nil] An instance of AndroidApk will be returned if no problem exists while analyzing. Otherwise nil. def self.analyze(filepath) return nil unless File.exist?(filepath) diff --git a/spec/android_apk_spec.rb b/spec/android_apk_spec.rb index 5e57fdf..17029db 100644 --- a/spec/android_apk_spec.rb +++ b/spec/android_apk_spec.rb @@ -25,6 +25,13 @@ end end + context "if duplicated sdk_version apk are given" do + let(:apk_filepath) { File.join(FIXTURE_DIR, "other", "duplicate_sdk_version.apk") } + it "should raise error" do + expect { subject }.to raise_error(AndroidApk::AndroidManifestValidateError, /Duplication of sdkVersion tag is not allowed/) + end + end + context "if invalid sample apk files are given" do context "no such apk file" do let(:apk_filepath) { File.join(FIXTURE_DIR, "other", "no_such_file") } diff --git a/spec/fixture/other/duplicate_sdk_version.apk b/spec/fixture/other/duplicate_sdk_version.apk new file mode 100644 index 0000000..0071f18 Binary files /dev/null and b/spec/fixture/other/duplicate_sdk_version.apk differ