Martynas
Martynas

Reputation: 627

Modify and test an Android library from GitHub

I use for example library Sweet Alert Dialog. I want to modify this library by adding text size customization to library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java.

public SweetAlertDialog setTitleText (String text, int size) {
         mTitleText = text;
         int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, getResources().getDisplayMetrics());
         if (mTitleTextView != null && mTitleText != null) {
             mTitleTextView.setText(mTitleText);
             mTitleTextView.setTextSize(height);
         }
         return this;
      } 

Now I want to test this library and use it if it does what it should do. I need that one time explanation to get it. At the moment GitHub is a little bit confusing.

UPDATE

I have added this library via

dependencies {

    compile 'cn.pedant.sweetalert:library:1.3'

}

Is there any way to just make your own compile path and test it? After branching the library or so?

Upvotes: 6

Views: 3183

Answers (2)

ken
ken

Reputation: 4077

Another method is to use JitPack.

It builds Git projects on demand and provides you with ready-to-use artifacts (jar, aar).

This way, you can fork the project, modify and test it. Then push it back to git and use that in your build script. Ideally, you would also create a pull request for your updates.

Step 1. Add the JitPack maven repository to the list of repositories:

url "https://jitpack.io"

Step 2. Add the dependency information:

  • Group: com.github.Username
  • Artifact: Repository Name
  • Version: Release tag, commit hash or -SNAPSHOT

Gradle example:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
dependencies {
    implementation 'com.github.User:Repo:Version'
}

Ensure you add the maven repo under allprojects, instead of buildscript.

Upvotes: 0

Clive Seebregts
Clive Seebregts

Reputation: 2034

The quickest way to obtain the library is to download it as ZIP file from GitHub.

Steps:

  1. Navigate to https://github.com/pedant/sweet-alert-dialog in your browser.
  2. Click on the Clone or download button (green).
  3. Click on the Download ZIP button (blue).

See below:

enter image description here

To make changes to Sweet Alert Dialog, we will import it into Android Studio.

Steps:

  1. Extract the contents of sweet-alert-dialog-master.zip file to disk e.g. c:\sweet-alert-dialog-master
  2. Start Android Studio
  3. From the Android Studio menu click File > New > Import Project
  4. Select the c:\sweet-alert-dialog-master folder and click Ok.
  5. Once the project is successfully imported, make necessary changes to the library.
  6. Use the sample project to test your changes.

If the changes made to the Sweet Alert Dialog meet your requirements, we can proceed to use the Android archive (*.aar) file in our project.

Steps:

  1. In Android Studio, open up an existing project that you want to use the Android archive file library.
  2. Copy the c:\sweet-alert-dialog-master\library\build\outputs\aarlibrary-release.aar file in the libs directory (create it if needed) of your project.
  3. Add the repositories section in the app\build.gradle file:

    repositories {
      flatDir {
        dirs 'libs'
      }
    }
    
  4. Add the following line to the dependencies section:

    compile (name: 'library-release', ext:'aar')
    
  5. Now the Sweet Alert Dialog contained in the Android archive file can be used in your app.

Upvotes: 8

Related Questions