gpt4 book ai didi

android - 在android中部署智能合约

转载 作者:行者123 更新时间:2023-11-30 00:04:31 26 4
gpt4 key购买 nike

我正在尝试使用 web3j 在 Android 上部署我的示例 solidity 智能合约。这是我的 solidity 合约:

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 上部署。谁能回答为什么?

最佳答案

使用这个:-

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

代替

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

打开 SDK 管理器并检查哪个是您在 26 中安装的最高 API 级别在 implementation 'com.android.support:appcompat-v7: **METION HERE** '

关于android - 在android中部署智能合约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49249752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com