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

如何在Android Studio中添加jbcrypt库?求助:无法引入mindrot.org的jbcrypt

Got it, let's walk through how to add jBCrypt to your Android Studio project—there are two straightforward methods to get this set up, depending on your workflow:

This is the easiest way since Gradle handles updates and dependencies automatically:

  • Open your project's settings.gradle file (for newer Android Studio versions). Make sure mavenCentral() is listed in the repositories block:
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral() // Ensure this line exists
        }
    }
    
  • Next, open your app module's build.gradle (located at app/build.gradle). Add the jBCrypt dependency to the dependencies block:
    dependencies {
        // Your other dependencies here...
        implementation 'org.mindrot:jbcrypt:0.11' // Use the latest version available
    }
    
  • Click the Sync Now button in the top-right corner of Android Studio. Once sync finishes, you can start using jBCrypt in your code:
    // Example: Hash a password
    String hashedPassword = BCrypt.hashpw("yourPlainTextPassword", BCrypt.gensalt());
    
    // Example: Verify a password
    boolean passwordMatches = BCrypt.checkpw("inputPassword", hashedPassword);
    

Method 2: Manually Import the JAR File

If you prefer to handle the JAR file directly (e.g., if you need a specific older version):

  • Download the jBCrypt JAR file from the official project page.
  • In your Android Studio project, right-click the app module -> New -> Directory, and name it libs.
  • Copy the downloaded JAR file into the libs folder.
  • Right-click the JAR file in Android Studio and select Add as Library. Choose your app module in the popup and click OK.
  • Gradle will automatically add this line to your app's build.gradle dependencies block:
    implementation files('libs/jbcrypt-0.11.jar')
    
  • Run a Gradle sync, and you're ready to use the library.

Notes to Keep in Mind

  • Min SDK Version: jBCrypt works with most Android versions (API 16 and above should be fine, but double-check if you're targeting very old devices).
  • ProGuard/R8 Obfuscation: If you're using code obfuscation, add this line to your proguard-rules.pro file to prevent jBCrypt classes from being stripped:
    -keep class org.mindrot.jbcrypt.** { *; }
    

内容的提问来源于stack exchange,提问作者Nic Parmee

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:27:52