在android中部署智能合约

时间:2018-03-13 06:38:10

标签: android solidity

我正在尝试使用web3j在Android上部署我的示例可靠性智能合约。这是我的稳固合同:

pragma solidity ^0.4.18;

contract Customer {
/* Constructor 
function Customer() public {
    name='kc';
    age=21;
}*/
string name;
uint age;

function setValues(string _name,uint _age) public{
    name=_name;
    age=_age;
}
function getValues() public constant returns(string,uint){
    return(name,age);
}
}

我使用web3j为上述合同生成了所有必需的abi和bin,并包含了所有必需的依赖项。这是我的build.gradle。

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.kc.wallet"
    minSdkVersion 24
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    jcenter()
    mavenCentral()
    maven {
        url "https://jitpack.io"
        url "https://dl.bintray.com/ethereum/maven/"
    }
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile ('org.web3j:core:3.1.1-android')//library for web3j
compile "org.ethereum:solcJ-all:0.4.8"
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile "io.reactivex.rxjava2:rxjava:2.0.2"

}

这里没有错误。 在MainActivity.java中,我在ContractName上发现了一个错误。

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button = findViewById(R.id.button);
    sample = findViewById(R.id.name);
    t = findViewById(R.id.display);
    final Web3j web3 = Web3jFactory.build(new HttpService());
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            //String s=sample.getText().toString();
            //t.setText(s);

            Web3ClientVersion web3ClientVersion = null;
            try {
                web3ClientVersion = web3.web3ClientVersion().sendAsync().get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            String clientVersion = web3ClientVersion.getWeb3ClientVersion();
            Credentials credentials = null;
            try {
                credentials = WalletUtils.loadCredentials("cheppanu", "/Users/unassigned2/AndroidStudioProjects/Wallet2/app/src/main/java/com/bodaty/bandha/wallet");
            } catch (IOException e) {
                e.printStackTrace();
            } catch (CipherException e) {
                e.printStackTrace();
            }
            Customer contract = Customer.load("0xe80cc6754ca60950ca5fb191b3f4eb625f6ebc7f", < Web3j >,<
            credentials >, GAS_PRICE, GAS_LIMIT);
            Type result = contract.deploy().send();
        }
    });

错误是

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

我无法在此Android上部署。谁能回答为什么?

1 个答案:

答案 0 :(得分:1)

使用: -

implementation 'com.android.support:appcompat-v7:26.0.3'

而不是

implementation 'com.android.support:appcompat-v7:26.1.0'

打开SDk管理器并检查哪一个是您安装的最高API级别26提及implementation 'com.android.support:appcompat-v7: **MENTION HERE** '

中的那个