You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加第三方Jar包后重建App遇Program type already present异常求助

Fixing 'Program type already present: jpos.JposException' in Android

Hey there, this error is a classic sign of duplicate class definitions in your project—and since your app worked perfectly before adding those four JARs, the issue is definitely that two (or more) of these JARs contain the same jpos.JposException class. Let's fix this step by step:

Step 1: Identify which JARs are causing the duplicate

First, we need to pinpoint the conflicting JARs:

  • Unzip each of your JAR files (bixolon_printer_v127.jar, icu4j-58_1.jar, jpos117-controls.jar, xerces.jar) and check if they contain a jpos/JposException.class file.
  • Chances are, both bixolon_printer_v127.jar (since it's a printer SDK built on JPOS) and jpos117-controls.jar include this class.

Step 2: Resolve the duplicate

You have two safe, actionable ways to fix this:

Option 1: Remove the redundant JAR

If the Bixolon printer SDK already includes all the JPOS functionality you need, try removing the jpos117-controls.jar entirely:

  1. Either delete the JAR from your libs folder, or comment out its line in your build.gradle.
  2. Update your dependencies block to look like this:
    dependencies {
        implementation files('libs/bixolon_printer_v127.jar')
        implementation files('libs/icu4j-58_1.jar')
        // implementation files('libs/jpos117-controls.jar') // Commented out to resolve duplicate
        implementation files('libs/xerces.jar')
        // Keep your other existing dependencies here
    }
    
  3. Clean your project (Build > Clean Project) then rebuild it.

Option 2: Exclude the duplicate class via Gradle

If you absolutely need both JARs, you can tell Gradle to exclude the conflicting class during packaging. Add this packagingOptions block inside your android section in build.gradle:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.andalus.mobilesales"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    // Add this block to exclude duplicate class
    packagingOptions {
        exclude 'jpos/JposException.class'
        // If you find more duplicate jpos classes, you can exclude the entire package:
        // exclude 'jpos/**'
    }
}

⚠️ Note: Only use this option if you're certain the excluded class is redundant—excluding necessary classes can lead to runtime crashes.

Step 3: Verify the fix

After making either change, run a full rebuild of your project. If the error disappears, test your printer functionality to ensure nothing broke from removing/excluding the duplicate class.

内容的提问来源于stack exchange,提问作者Mohammad amarneh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:38:37