Search code examples
javaandroidgithubandroid-library

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?


Solution

  • 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.