To make your own library you have to do following thing:
1. making library for android needs parent app to run and access the library things.For this if you have already any project where u wants to make library that also fine or u can create a new android project and than do the following thing:-
To invoke SDK we need to add this in our app gradle :-
To call the SDK first Activity or to inter inside the SDK we have do like following :-
to get the bundle from parent app :-
1. making library for android needs parent app to run and access the library things.For this if you have already any project where u wants to make library that also fine or u can create a new android project and than do the following thing:-
To invoke SDK we need to add this in our app gradle :-
dependencies {
compile project(':addnum')
}
To call the SDK first Activity or to inter inside the SDK we have do like following :-
addBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // if u wants to pass any data to the SDK sent it into bundle we can use all other method to do this
Bundle bundle = new Bundle(); bundle.putString("name","Supriya"); bundle.putString("id","123"); Intent intent = new Intent(MainActivity.this,AddNumberActivity.class); intent.putExtras(bundle); startActivity(intent); } });SDK code will be like following (AddNumberActivity) :-
to get the bundle from parent app :-
Bundle bundle = getIntent().getExtras();
if(bundle != null) {
String name = bundle.getString("name"); String id = bundle.getString("id");
}
tvname.setText(name); tvid.setText(id);
btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ed1.getText().toString() != null && ed2.getText().toString() != null) { float result = Float.parseFloat(ed1.getText().toString()) + Float.parseFloat(ed2.getText().toString()); tvResult.setText(String.valueOf(result)); } } });
Note:-
1. To generate .aar file please clean the project (Build > Clean Project ).
2. And than Rebuild the project (Build > Rebuild Project ).
3. To see the .aar file please choose view code as project.
4. And than click on sdk addnum > build > outputs > aar.
5. Here right click on .aar file and click on an option Reveal in Finder .
6. Now you can copy your .aar file to use in another project.
No comments:
Post a Comment